Expr

Evaluate a mathematical expression.

Syntax

Expr expression

Comments

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

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.

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

If