Chapter 18
Mathematical expressions

Since INScore version 1.20, mathematical expressions have been introduced as messages arguments. These expressions allows to compute values at parsing time.

18.1 Operators

Basic mathematical expressions are supported. They are listed below.

PICT

Note that matharg could be a mathexpr as well (see section 18.2).

EXAMPLE
Some simple mathematical expressions used as message parameters:

/ITL/scene/myObject x 0.5 * 0.2;
/ITL/scene/myObject y ($var ? 1 : -1);

Boolean operations are the following:

mathbool PICT

EXAMPLE
Compare two variables:

/ITL/scene/myObject x ($var1 > $var2 ? 1 : -1);

18.2 Arguments

Arguments of mathematical operations are the following:

matharg PICT

18.3 Polymorphism

Since INScore’s parameters are polymorphic, the semantic of the operations are to be defined notably when applied to non numeric arguments. Actually, a basic OSC message parameter type is between int32, float32 and string. However, due to the extension of the scripting language, parameters could also be arrays of any type, including mixed types (e.g. resulting from variable declarations).

18.3.1 Numeric values

For numeric arguments, automatic type conversion is applied with a precedence of float32 i.e. when one of the argument’s type is float32, the result is also float32 (see Table 18.1).





arg1arg2 output



int32int32 int32
float32int32 float32
int32float32float32
float32float32float32




Table 18.1: Numeric operations output

18.3.2 Strings

For string parameters, operations that have an obvious semantic (like + applied to two strings) are defined (see Table 18.2) , the others are undefined and generate an error (see Table 18.3).





operationevaluates to comment



string + stringstring concatenate the two strings
string + numstring + string(num) num is converted to string
num + stringstring(num) + string "
@max(stringstring)string select the largest string
@min(stringstring)string select the smallest string




Table 18.2: Supported operations on strings




operation comment


string op stringwhere op is in [- * / %]
string op num "
num op string "
-string
prefixed or postfixed string



Table 18.3: Non supported operations on strings

Boolean operations are supported on string only when both arguments are strings (see Table 18.4). Other types combination generate an error.




boolean operation evaluated as


string == string regular strings comparison
string > stringalphabetical strings comparison
string >= string "
string < string "
string <= string "



Table 18.4: Supported boolean operations on strings

18.3.3 Arrays

For arrays, the operation is distributed inside the array elements:

arg op[v1 ...vn]:= [arg opv1 ...argop vn]
or
[v1 ...vn]op arg := [v1 oparg...vn op arg]

When both parameters are arrays, the operation is distributed from one array elements to the other array elements when the arrays have the same size and it generates an error when the sizes differ:

[a1 ...ai]op[b1 ...bi]:= [a1 opb1 ...ai op bi ]

Boolean operations on arrays are evaluated as the logical and of it’s element’s boolean values and generate an error when the arrays sizes differ.