Transform Reference Guide


Evaluate a mathematical expression.


Expr expression


Expr evaluates mathematical expressions in a format resembling programming languages like C, Java or Tcl. The expression is composed of numbers, arithmetic operators, math functions like sin or log and variables.

Integer, floating-point, and complex numbers can be used as constants within an expression.

Variables are alphanumeric strings preceded by a $. The first letter or pair of letters after the $ determine the type of the variable:

i: integer
f: float
d: double
c: complex
cd: double-precision complex
s: audio samples (floating-point)
ds: double-precision audio samples
is: integer audio samples
ss: 16 bit audio samples
l: list

For example $i1 would be an integer variable and $sfoo would be a audio-sample variable. For each variable used in the expression, an inlet of the same name and type is created for the Expr transform. So the expression $i1 + $f2 / $f3 would have one Integer inlet and two Float inlets.

If a variable name does not use any of the above prefixes, it is treated as an ordinary OSW variable (i.e., as used by Get/Put or the $ operator in transform arguments). If the variable exists elsewhere in the patch (e.g., as a transform variable or a free variable), it is used in the expression. Otherwise, a new inlet of type Any is added to the Expr transform is created.

The valid operators are listed below, in order of decreasing precedence:

Exponentiation (ab). Valid for all operand types.
Factorial (e.g. 3! = 3*2*1 = 6). Only works with integer operands.
Unary minus (negation). Valid for all operand types.
Logical negation (NOT). Only works with integer and boolean operands.
* / %
Multiplication, division and modulus (remainder). Modulus does not currently work with complex numbers.
+ -
Addition and subtraction. Valid for all operand types
<< >>
Bitwise left shift and right shift operations. Valid only for integer operands.
?& ?| ?^
Bitwise AND, OR and XOR. The "?" is added to the traditional C symbols to distingish them from other OSW operators, such as ^ used for exponentiation.
< <= >= >
Comparison operators. Not valid for complex numbers.
== !=
Equality and inequality. Valid for all operand types.
&& ||
Logical AND and OR. Valid only for integer and boolean operands.

Operator precedence can of course be overriden using parentheses.

Expr understands the following math functions:

See the documentation for the standalone versions of these functions for their valid argument types. It is possible to extend the set of available functions via special external libraries.

The expression is evaluated whenever a new value is received via any of the inlets. A single outlet is provided to transmit the result of the expression evaluation. If no variables are specified in the expression (i.e., the expression is constant), a single inlet of type unit is created. When this inlet receives a unit value, the constant expression is evaluated.

See Also


Open Sound World User Guide
© 2000-2004 Amar Chaudhary. All rights reserved.