A REALbasic plug-in for Runtime Mathematical Expression Evaluation
This is both a PPC and a Carbon/OS X Plug-in.
EquationEvaluator is based on Robert Douglas' Macintosh port of Mark Morley's Expression Evaluator (which can be found in DOS code repositories under the name C-EVAL).
This REALbasic version is a plug-in with just one function that takes a string (a mathematical expression) as an argument and returns a double.
Supported mathematical functions include:
You give the function (called JEE) a string with the expression you would like evaluated, and it will return the value as a double.
The variable assignment feature makes it possible to assign up to 50 variables (each with a name up to 15 characters long). You can assign the variables before you give the expression (as in "x=3, y=2, x+y") or in the middle of an expression (as in "3+(x=4) + x" which should return 11). Or you can have an expression evaluated as part of the assignment, and used later on in another expression (as in "x=3, y=x+2, x+y" which returns 8). Note that if you do the assignment before the expression then you need to follow the assignment with a comma (,) so that the parser knows where the assignment stops and the expression begins.
EquationEvaluator follows the standard math rules for determining which operations go first (multiplication/division before addition/subtraction, etc.). You can also group parts of your expression with parentheses ( "(" and ")" ) if you want to be sure of the order of operations.
Warning: EquationEvaluator does not evaluate scientific (powers of ten) notation. If you try this assignment "x=3E5" (meaning "x=300000"), EquationEvaluator will become confused and will not return the correct value (probably it will return 0). The best solution is to pre-process any strings with scientific notation so that they replace the "E" with "*10^" (so our assignment above would be "x=3*10^5").
JEE("7+11*5") returns 62
Return to Tamara's Homepage