Mathematical calculation of type printf

I am looking for a flexible, but also significantly quicker way to easily convert values ​​and calculations based on descriptive strings of a calculator.

For example, something like this:

double r = 1.0; double d = mathf( "sin(%1)+2*%2", r, M_PI ); double e = mathf( "%1 / 180.0 * %2", r, M_PI ); 

It is important to think that math operations can be evaluated at runtime and loaded from the configuration file. I even considered some integration of the scripting language, but it seems that it is not so smooth and fast?

Any ideas if there is something like mathf for C ++?

+6
source share
1 answer

Try to find a little more. This is a pretty common thing. It parses, and every compiler does it. This is a bit like a parser.

Solve an equation from a string to result in C

Appreciate the simple mathematical expression of a string

Convert string to math grade

etc.

There are two ways to do this, one is to write your own, and the second is to find a library that seems like what you are looking for. I don’t know anything like this in standard C ++ libraries, in ruby ​​and a bunch of other languages, you can just evaluate the string, but in C ++ you probably have to borrow a library from the Internet or something. Try this last link, it looked promising for this.

+5
source

All Articles