User Guides

Expression Reference

Cantabile includes and expression evaluation engine that is used for evaluating the expressions in Gain Control Curves.

Data Types

The expression engine only supports double precision floating point numbers.

For boolean operations, any non-zero value is considered true and any function or operator that returns a boolean value will return 1 for true and 0 for false.

Functions

Functions are called by name with parameters enclosed in round brackets and separated by commas.

eg: pow(10, 3)

Functions are defined with a function prototype as the JSON key and the value the expression:

eg: "mySillyAddFunction(a,b)": "a+b"

Constants

Constants are functions with no parameters and may be defined as JSON numeric value:

eg: "curveSlope": 60

or as an expression:

eg: "curveSlope": "120/2"

Operators

The expression engine supports the following operators:

+
Add
-
Subtract and negative
*
Multiply
/
Divider
? :
Ternary (aka conditional) operator
<, <=, >, >=, ==, !=
Comparison
!
Logial Not
&&
Logical And
||
Logical Or
( )
Grouping

Built-in Functions

The expression engine includes the following built-in functions. The unit for all angles is radians.

abs(x)
Absolute value
acos(x)
Arc-cosine
asin(x)
Arc-sine
atan(x)
Arc-tangent
atan2(x,y)
Arc-tangent of (x,y)
ceiling(x)
Round to more positive value
cos(x)
Cosine
cosh(x)
Hyperbolic Cosine
e
Constant e
exp(x)
e raised to the power of x
floor(x)
Round to less positive value
log(x)
Natural (base e) logarithm
log(x, b)
Base b logatirhm
log10(x)
Base 10 logarithm
min(x,y)
The smaller value of x and y
max(x,y)
The larger value of x and y
pi
Constant pi
pow(x, y)
x raised to the power y
round(x)
Round x to the closest whole enumber
sign(x)
Returns -1, 0, or 1 matching the sign of x
sin(x)
Sine
sinh(x)
Hyperbolic Sine
sqrt(x)
The square root of 'x'
tan(x)
Tangent
tanh(x)
Hyperbolic Tangent
truncate(x)
Remove the fractional part of a x
isnan(x)
Returns 1 if x is not a number, else 0
isinfinity(x)
returns 1 if x is infinity, else 0
infinity
The constant +infinity
nan
The constant for non a number
epsilon
The smallest expressible double precision number
maxDouble
The most positive supported double precision number
minDouble
The most negative supported double precision number
epsilonFloat
The smallest expressible single precision number
maxFloat
The most positive supported single precision number
minFloat
The most negative supported single precision number
toDb(x)
Converts a scalar value to decibels
toDb(x,y)
Converts a scalar value x to decibels with a floor of y dB. (ie: a smaller value will be returned as negative infinity)
fromDb(x)
Converts decibels to scalar
fromDb(x, y)
Converts decibels to scalar with a floor of y dB (ie: a smaller value will be returned as 0);