Equation Compiler Plugin

Some years ago I purchased a non-commercial license for Kevin Raner's Equation Compiler for the PowerPC microprocessor. While an application is running, the PPC version of his compiled C source software can parse a user entered text string containing an equation (or, more properly, a function) and compile it into PPC machine code and store it into a Handle. The Windows version does the same for x86 machine code. A function pointer can then be used by the program in the same way as for any other function installed at application compile time. This will be much faster than having to interpret the equation every time it is used.

Versions 3.0 and 3.1 are a complete rewrite of my previous Equation Compiler Plugin. This intermediary between Kevin Raner's Equation Compiler and REALbasic is much more flexible than the original.

It allows a user entered equation which can contain up to six independent variables. The names of these variables are set by the user. The names pretty much follow the rules for REALbasic variable names, except that the underscore, _, is not permitted.

Only two functions are needed for the plugin. They are compile() and evaluate(), both of which can take a variable number of arguments.

The compile() function can take from 1 to 7 arguments. The first is the function text. The remaining are the string names of the user variables. Their order defines how the plugin uses the arguments of the evaluate function. The return type of compile() is a Boolean, true for a good compile, false for a bad one.

The evaluate() function takes from 0 to 6 arguments. These are the input double values for the variables defined with compile{}. With no argument the function has no variables, as say 2*exp(3.5). The return type of evaluate() is a double which results from evaluating the function.

Equations are to be input in C format. In addition to explicit numbers, any combination of the following can be used in the equation text:

The symbols for the allowed arithmetic operators are:

+ addition
- subtraction, unary minus
* multiplication
/ division
^ exponentiation

Functions

sin(x), sine
cos(x), cosine
tan(x), tangent
asin(x), arcsine
acos(x), arccosine
atan(x), arctangent

the following six trigonometric functions treat the angle in degrees:
sind(x) sine
cosd(x) cosine
tand(x) tangent
asind(x) arcsine
acosd(x) arccosine
atand(x) arctangent

ln(x), natural logarithm (base e)
log(x), common logarithm (base 10)
log2(x), binary logarithm (base 2)
exp(x), natural exponent (e^x)
exp10(x), common exponent (10^x)
exp2(x), binary exponent (2^x)
sinh(x), hyperbolic sine
cosh(x), hyperbolic cosine
tanh(x), hyperbolic tangent
asinh(x), arc hyperbolic sine
acosh(x), arc hyperbolic cosine
atanh(x), arc hyperbolic tangent
theta(x), {0 if x<0, .5 if x=0, 1 if x>0}
sqrt(x), square root
sqr(x), x^2
abs(x), {x if x>=0, -x if x<0}
sign(x), {+1 if x>0, 0 if x=0, -1 if x<0}
step(x,y), {0 if x=y}
box(x,y,z), {1 if x<=y<=z, 0 if x>y or y>z}
pi, Pi

For example, here is a possible function:
x*tan(x) - sqrt(b*b - x*x)

I can add additional functions if users request them.

Applications using my plugin (a so-called fat plugin) can run under Windows or in the classic Mac OS 8.x to 9.x environment or as a Carbon application which also can run under Mac OS X. It's the programmers choice as to what environments to support.

Equation Compiler Plugin was programmed in C++ and is based on Kevin Raner's Equation Compiler. http://www.krs.com.au/
Equation Compiler is no longer listed on his web site.

Kevin has graciously allowed me to distribute my plugin provided that i) the source code is not disclosed and that ii) the plugin is not used commercially. He also says: "If a third party did want to use your plugin commercially I would give my permission if the third party purchased a commercial license for my portion of the intellectual property."
His email address is info@krs.com.au.


Download Equation Compiler Plugin 3.1. The non-English (NE) version returns the integer error code instead of stating the error in a REALbasic message box.

EqnCompPlugin.hqx (100 KB)
EqnCompPluginNE.hqx (80 KB)
EqnCompPlugin.zip (88 KB) For Windows version of REALbasic


Back To Bob Delaney's Home Page