You want in fact to read expressions not numbers. So you want to evaluate these expressions (in some environment, which defines what is the meaning -or binding- of variables).
So if you insist on keeping your requirement, you want an evaluator, i.e. an interpreter.
A possible way would be to embed some existing interpreter, like Lua, Guile, etc.
Otherwise, you want a parser for your expression language (which you should specify on paper, including its formal syntax -e.g. using BNF- and its semantics), and an evaluator for the parsed ASTs. Formally speaking your M_PI
looks like a mathematical variable, and has its value in some environment.
If you want to go that route, read some tutorial textbook on interpreter and compiler implementations. The wikipage on recursive descent parser is explaining how to do something similar to your needs. Google also on arithmetic expression evaluator, you'll get a lot of relevant hits.
The documentation on GNU bison (a parser generator, sometimes called a compiler-compiler) contains a section: §2.2 infix notation calculator which looks similar to your needs.