Some years ago I purchased a non-commercial license for Kevin Raner's

Equation Compiler for the PowerPC microprocessor. While an application

is running 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. 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.

I have succeeded in compiling Equation Compiler Plugin for REALbasic.

This plugin brings most of the functionality of Equation Compiler to a

REALbasic programmer.

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

http://www.*-*-*.com/

Compiler on his site.

The API for the plugin consists of three REALbasic functions or

subroutines. They are:

compile theEquation.text

Here "theEquation" is the name of a REALbasic EditField where a user

would enter an equation. Of course, the programmer could use any other

name than "theEquation". If there is an error a REALbasic message box

will appear with information about the error.

setCoeffs a, b, c, d, e

The arguments are REALbasic doubles. The plugin uses these arguments to

update a coeff[ ] array for Equation Compiler. The user can use none,

any, or all of these coefficients in the entered equation. The

programmer should provide a means for providing values for these

coefficients, if used, before passing them to the plugin by this

subroutine.

evaluate(x)

is a function which evaluates the compiled equation using the REALbasic

double x (or any other name) as argument, and returns the REALbasic

double value. The entered equation always uses x as the independent

variable.

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

PowerPC functions

sin(x) sine

cos(x) cosine

tan(x) tangent

asin(x) arcsine

acos(x) arccosine

atan(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, 1 if x>=y}

box(x,y,z) {1 if x<=y<=z, 0 if x>y or y>z}

? or 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 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.

You can download my plugin and supporting files from my web site:

http://www.*-*-*.com/

I've included the REALbasic project "Newton's Method.rb" which shows

how to use my plugin. It compiles "Newton's Method". Open "Newton's

Method desc.txt" which describes its use.

Bob Delaney