phpInDev

Math-C - math library

Math-C is a small GML library that provides a function called math_evaluate. Depending on the evaluation type you give to it as an argument, it will either execute or compile (into GML) the given expression. So, for example, by giving "1+1" as an argument to the math_execute function, it will return a real value "2". All different operators are supported and many functions too.

Math-C can handle equations of pretty much any length. It also handles the calculation order properly so that, for example, "2 + 2 * 2" would return 6 and not 8. The script is also has support for functions such as sin or cos and includes constants pi and e. Powers are also supported with the "^" operator. Math-C handles all calculation without using the execute_string and also provides ability to customize it by adding functions and constants.

If you are interested, check the download. It comes with an example of how to use the script, which also lets you try around it freely. The download also includes complete documentation on how Math-C's expression syntax works, although it shouldn't be hard to figure out, because it's basically the same as in many scientific calculators.