.TH EXPR 3carl CARL
.SH NAME
expr - cmusic-like expression evaluator
.SH SYNOPSIS
.LP 
.nf
.B float expr(expression)
.B char *expression;
.B extern int exprerr;
.fi
.SH DESCRIPTION
.B expr()
provides expression evaluation similar to that in
.I cmusic(1carl).
It takes the string of the expression to be evaluated and returns
the floating point result.
Expressions may contain several types of operands and operators.  
Expressions must not include blank spaces.
The syntax of expressions is a subset of that available in
.I cmusic.
The current list of possibilities
is as follows:
.PP
.RS .25i
.SH OPERANDS:
.IP NUMBERS 15
Numbers may have three bases; all are of type float
whether they include a decimal point or not.
.RS .5i
.IP decimal		
Any string of digits, which either includes a decimal
point, or which does not include a decimal point.
.IP hexadecimal	
If a number does not include a decimal point and starts
with the characters 0x, then base 16 is interpreted.
.IP octal		
If a number does not include a decimal point and
starts with the digit 0, base 8 will be interpreted.
.RE
.SH OPERATORS:
.IP PARENTHESES
Parentheses must balance, and may be used freely to establish
operator precedence.  Function arguments should be enclosed in
parentheses.
.IP UNOPS 
The following are unary operators available in expressions in order of
precedence, with the first set of operators done before anything in the
second set.  Unary operations are done before binary operations, and
binary operations are done before post operations.
.RS .5i
.IP "{sin,cos,atan,ln,exp,floor,abs,sqrt,rand}"
(These are the standard trigonometric functions sine, cosine, 
and arctangent, from the UNIX math library, as well as the 
natural logarithm, exponential, floor, absolute value, and 
square root functions.  Rand is a function which returns a 
random value between 0 and its (positive) argument.)
.IP {-} 10
(Unary minus, as in -3*p5)
.RE
.SH
BINOPS 
.PP
The precedence is as shown below: ^ and % are done before * and /,
and * and / are done before + and -.
.RS .25i
.IP {^,%} 10
(3^.5 means 3 to the .5 power; 397%17 means 397 modulo 17)
.IP {*,/} 10
(5*79.2 means 5 times 79.2; 9/5 means 9 divided by 5 (float result))
.IP {+,-} 10
(3+3 means 3 plus 3; 3-8 means 3 minus 8)
.RE
.SH
POSTOPS 
.PP
Post operators are done last. They generally modify the resulting value
of the expression which preceeds them.
.RS .25i
.IP dB  
converts dB (logarithmic) to linear scale.
Example: -6dB = 10^(-6/20) = 0.5 (approx.).
.IP K   
converts K to units.
Example: 8K = 8 * 1024 = 8192.
.IP k   
converts k to units.
Example: 8k = 8 * 1000 = 8000.
.IP Deg 
converts degrees to radians.
Example: 180Deg = (180 / 360) * TWOPI = 3.14159.
.IP MM  
converts metronome marks to seconds per beat;
example: 120MM = 60/120 = .5 seconds per beat.
.IP IS  
computes the sum of the first N inverse terms,
i.e., 3invs = 1 + 1/2 + 1/3. 0IS = 0 by definition.
.RE
.SH FILES
/usr/local/lib/libcarl.a.
.SH AUTHOR
F. R. Moore
.SH SEE ALSO
sfexpr(3carl), cexpr(1carl), xform(1carl).
.SH BUGS
The expression format is a subset of that in
.I cmusic(3carl).
Not all things available there are necessarily available here.
In particular, postoperators that depend on sampling rate are not
available, nor are P fields, V variables, functions, blocks, etc.
