Purpose

This module performs arithmetic operations on scalars and vectors. Up to eight expressions can be evaluated in parallel.

Usage

Enter the arithmetic expression you want to calculate. You can specify additional variables in the respective fields.

Output type

The type that is used for calculation and for the output is determined from the expression and used variables. The following table shows which conditions that change the calculation and output type. If no condition is met, the calculation and output type will be MLint.

Condition Output type is at least
Decimal number (e.g. ‘1.2’) MLfloat
Constant ‘pi’ MLdouble
Double variable (d1-d12) MLdouble
Trigonometric and certain other functions:
cos, sin, tan, acos, asin, atan,
cosh, sinh, tanh, exp, log,
log10, log2, sqrt, root
MLfloat
Vector variable (v1-v6) or anonymous vector vec3
Bitwise operators (&, |, ^) MLuint8

Support of registered types

The dimension of input and output types is always the same. This means that you cannot, for example, calculate the norm of a vector. Instead, many functions that are available for registered types will be calculated component-wise (e.g. cos on each component instead of cos on a whole vector). However, many functions are not supported at all for certain types. Note that there will be no error message if you try to use incompatible types and functions. The output image will simply not be computed. See the tables below for more information.

This table shows the available types and their association to type groups (for ease of read):

Type group ML types
Standard MLuint8, MLint, MLfloat, MLdouble
Vector vec3

This table shows which type group supports which functions. While ‘Y’ and ‘-’ indicate (native) support and no support, respectively, ‘C’ indicates support by means of component-wise calculation.

Function Standard Vector
Basic functions
+ Y Y
- Y Y
* Y C [1]
/ Y C [2]
% Y -
- (unary) Y Y
min Y C
max Y C
diff Y C
abs Y C
sgn Y C
mix Y C
clamp Y C
absmin Y C
absmax Y C
[1]Equivalent to .*
[2]Equivalent to ./
Trigonometric functions
cos Y C
sin Y C
tan Y C
cosh Y C
sinh Y C
tanh Y C
acos Y -
asin Y -
atan Y -
atan2 Y -
Exponential and logarithmic functions
pow Y C
sqr Y C
root Y -
sqrt Y C
exp Y C
log Y C
log10 Y C
log2 Y C
Logical functions
== Y Y
!= Y Y
< Y C
> Y C
<= Y C
>= Y C
and Y -
or Y -
xor Y -
imp Y -
! Y -
& [3] Y -
| [3] Y -
^ [3] Y -
[3](1, 2, 3) for unsigned integer types only
Rounding functions
floor Y C
ceil Y C
round Y C
Functions on vector values
.* - Y
./ - Y
norm - Y
dot - Y
cross - Y
length - Y

Operator precedence

The following table lists the precedence of infix functions, where a higher precedence group means higher precedence.

Precedence group Functions
1 imp
2 or/||
3 xor
4 and/&&
5 ==, !=
6 <, >, <=, >=
7 +, -
8 *, /, %, .*, ./

Details

The arithmetic language over “numbers” (scalars and vectors) used in this module combines functions and arguments to form an arithmetic expression.

If you enter an invalid expression, a message indicating the error will be displayed in the module panel.

Functions

Function Syntax Description
Basic functions
+ a + b Addition
- a - b Subtraction
* a * b Multiplication
/ a / b
Division
If b is zero, a domain error occurs
% a % b Modulo
- - a Unary minus (invert)
min min(a, b)
Minimum of arguments
Applied component-wise to vector values
max max(a, b)
Maximum of arguments
Applied component-wise to vector values
diff diff(a, b) Difference (absolute value after subtraction)
abs abs(a) Absolute value
sgn sgn(a) Signum (result is 1 for positive values, 0 for zero and -1 for negative values)
mix mix(a, b, c) Mix b to a, weighted by c, using a + c*( b - a )
clamp clamp(a, b, c) Clamp c to range [ a; b ]
absmin absmin(a, b)
Returns the argument that has the minimum absolute value.
If the absolute values are equal, the minimum is returned
Applied component-wise to vector values
absmax absmax(a, b)
Returns the argument that has the maximum absolute value.
If the absolute values are equal, the maximum is returned
Applied component-wise to vector values
Trigonometric functions
cos cos(a) Cosine
sin sin(a) Sine
tan tan(a) Tangent
cosh cosh(a) Hyperbolic cosine
sinh sinh(a) Hyperbolic sine
tanh tanh(a) Hyperbolic tangent
acos acos(a)
Inverse cosine
If a is outside of range [-1;1], a domain error occurs
asin asin(a) Inverse sine | If a is outside of range [-1;1], a domain error occurs
atan atan(a) Inverse tangent
atan2 atan2(y, x) atan2 (note reversed argument order)
Exponential and logarithmic functions
pow pow(a, b) a raised to the power of b
sqr sqr(a) a squared
root root(a, b)
b-th root of a
If b is zero, a domain error occurs
sqrt sqrt(a)
Square root
If a is negative, a domain error occurs
exp exp(a) e raise to the power of a
log log(a)
Natural logarithm
If a is zero or negative, a domain error occurs
log10 log10(a)
Decadic logarithm
If a is zero or negative, a domain error occurs
log2 log2(a)
Binary logarithm
If a is zero or negative, a domain error occurs
Logical functions
== a == b Equality
!= a != b Inequality
< a < b
a is less than b
Applied component-wise to vector types
For those types, the comparison is true if all components compare true
> a > b
a is greater than b
Applied component-wise to vector types
For those types, the comparison is true if all components compare true
<= a <= b
a is equal to or less than b
Applied component-wise to vector types
For those types, the comparison is true if all components compare true
>= a >= b
a is equal to or greater than b
Applied component-wise to vector types
For those types, the comparison is true if all components compare true
and
&&
a and b
a && b
Logical AND
or
||
a or b
a || b
Logical OR
xor a xor b Logical XOR (exclusive OR)
imp a imp b Logical implication
! !*a* Logical NOT
& a & b Bitwise AND
| a | b Bitwise OR
^ a ^ b Bitwise XOR (exclusive OR)
Rounding functions
floor floor(a) Floor value
ceil ceil(a) Ceil value
round round(a) Rounded value
Functions on vector values
.* a .* b Component-wise multiplication
./ a ./ b Component-wise division
norm norm(a) Normalize a to unit vector
dot dot(a, b) Dot product
cross cross(a, b) Cross product
Index v[expr]
expr is evaluated to a value which is then used to access a component of v
expr must evaluate to an integer in [0;2], otherwise an error occurs
v must be a vector variable (v1-v6)
Vector [e1,e2,e3]
e1, e2 and e3 are evaluated to values which are then used to fill
the components of a vector
length length(a) Length of vector

Arguments

A function arguments can be anything of the following:

  • A literal value (for example 5, -5 or 1.3, but not 2.) When the expression is evaluated over vectors, a literal number is converted to a value of that type where all components are set to that number
  • A literal vector (see above), for example [1, i1+sin(f1), max(i2, 5)]
  • A built-in constant: pi
  • A variable (i1-i6, d1-d12, v1-v6) The variable is evaluated to the value set in the module panel

Legacy Issues

The variables f1-f6 and ld1-ld6 redirect to d1-d6 and d7-d12 both as fields and as variables in the expression.

Tips

Referencing expressions

You cannot reference other expressions in the same Calculator directly. It is, however, possible to connect the result field of an expression to a variable field that is used by another expression. Note that the Calculator cannot see this dependency (and updates are blocked by the field notification mechanism anyway), so you have to apply twice to get the correct result in the second expression (and more often if you chained several expressions).

Windows

Default Panel

../../../Modules/ML/MLCalculator/mhelp/Images/Screenshots/Calculator._default.png

Parameter Fields

Field Index

a.x:: Float d6: Double Is valid (resultValid5): Bool
a.y:: Float d7: Double Is valid (resultValid6): Bool
a.z:: Float d8: Double Is valid (resultValid7): Bool
Apply: Trigger d9: Double Is valid (resultValid8): Bool
Apply Mode: Enum e.x:: Float modeVector1: Bool
b.x:: Float e.y:: Float modeVector2: Bool
b.y:: Float e.z:: Float modeVector3: Bool
b.z:: Float Expression a: String modeVector4: Bool
c.x:: Float Expression b: String modeVector5: Bool
c.y:: Float Expression c: String modeVector6: Bool
c.z:: Float Expression d: String modeVector7: Bool
clearExpressions: Trigger Expression e: String modeVector8: Bool
clearScalarVariables: Trigger Expression f: String Scalar Result a: Double
clearVectorVariables: Trigger Expression g: String Scalar Result b: Double
Comment (exp1Comment): String Expression h: String Scalar Result c: Double
Comment (exp2Comment): String f.x:: Float Scalar Result d: Double
Comment (exp3Comment): String f.y:: Float Scalar Result e: Double
Comment (exp4Comment): String f.z:: Float Scalar Result f: Double
Comment (exp5Comment): String g.x:: Float Scalar Result g: Double
Comment (exp6Comment): String g.y:: Float Scalar Result h: Double
Comment (exp7Comment): String g.z:: Float Status: String
Comment (exp8Comment): String h.x:: Float v1: Vector3
Comments (scalarVariablesComment): String h.y:: Float v2: Vector3
Comments (vectorVariablesComment): String h.z:: Float v3: Vector3
d.x:: Float Handling on Domain Error: Enum v4: Vector3
d.y:: Float i1: Integer v5: Vector3
d.z:: Float i2: Integer v6: Vector3
d1: Double i3: Integer Vector Result a: Vector3
d10: Double i4: Integer Vector Result b: Vector3
d11: Double i5: Integer Vector Result c: Vector3
d12: Double i6: Integer Vector Result d: Vector3
d2: Double Is valid (resultValid1): Bool Vector Result e: Vector3
d3: Double Is valid (resultValid2): Bool Vector Result f: Vector3
d4: Double Is valid (resultValid3): Bool Vector Result g: Vector3
d5: Double Is valid (resultValid4): Bool Vector Result h: Vector3

Visible Fields

Status

name: statusBar, type: String, persistent: no

When the expression is invalid or an error occurred during evaluation, an error message is shown here.

Expression a

name: exp1, type: String, deprecated name: expression0,expression

Enter an expression.

Scalar Result a

name: resultScalar1, type: Double, persistent: no, deprecated name: scalarResult0,calcOutput

Scalar result of expression a.

Vector Result a

name: resultVector1, type: Vector3, persistent: no, deprecated name: vectorResult0,vecOutput

Vector result of expression a.

Is valid (resultValid1)

name: resultValid1, type: Bool, persistent: no

Indicates if the result of expression a is valid.

Expression b

name: exp2, type: String, deprecated name: expression1

Enter an expression.

Scalar Result b

name: resultScalar2, type: Double, persistent: no, deprecated name: scalarResult1

Scalar result of expression b.

Vector Result b

name: resultVector2, type: Vector3, persistent: no, deprecated name: vectorResult1

Vector result of expression b.

Is valid (resultValid2)

name: resultValid2, type: Bool, persistent: no

Indicates if the result of expression b is valid.

Expression c

name: exp3, type: String, deprecated name: expression2

Enter an expression.

Scalar Result c

name: resultScalar3, type: Double, persistent: no, deprecated name: scalarResult2

Scalar result of expression c.

Vector Result c

name: resultVector3, type: Vector3, persistent: no, deprecated name: vectorResult2

Vector result of expression c.

Is valid (resultValid3)

name: resultValid3, type: Bool, persistent: no

Indicates if the result of expression c is valid.

Expression d

name: exp4, type: String, deprecated name: expression3

Enter an expression.

Scalar Result d

name: resultScalar4, type: Double, persistent: no, deprecated name: scalarResult3

Scalar result of expression d.

Vector Result d

name: resultVector4, type: Vector3, persistent: no, deprecated name: vectorResult3

Vector result of expression d.

Is valid (resultValid4)

name: resultValid4, type: Bool, persistent: no

Indicates if the result of expression d is valid.

Expression e

name: exp5, type: String, deprecated name: expression4

Enter an expression.

Scalar Result e

name: resultScalar5, type: Double, persistent: no, deprecated name: scalarResult4

Scalar result of expression e.

Vector Result e

name: resultVector5, type: Vector3, persistent: no, deprecated name: vectorResult4

Vector result of expression e.

Is valid (resultValid5)

name: resultValid5, type: Bool, persistent: no

Indicates if the result of expression e is valid.

Expression f

name: exp6, type: String, deprecated name: expression5

Enter an expression.

Scalar Result f

name: resultScalar6, type: Double, persistent: no, deprecated name: scalarResult5

Scalar result of expression f.

Vector Result f

name: resultVector6, type: Vector3, persistent: no, deprecated name: vectorResult5

Vector result of expression f.

Is valid (resultValid6)

name: resultValid6, type: Bool, persistent: no

Indicates if the result of expression f is valid.

Expression g

name: exp7, type: String, deprecated name: expression6

Enter an expression.

Scalar Result g

name: resultScalar7, type: Double, persistent: no, deprecated name: scalarResult6

Scalar result of expression g.

Vector Result g

name: resultVector7, type: Vector3, persistent: no, deprecated name: vectorResult6

Vector result of expression g.

Is valid (resultValid7)

name: resultValid7, type: Bool, persistent: no

Indicates if the result of expression g is valid.

Expression h

name: exp8, type: String, deprecated name: expression7

Enter an expression.

Scalar Result h

name: resultScalar8, type: Double, persistent: no, deprecated name: scalarResult7

Scalar result of expression h.

Vector Result h

name: resultVector8, type: Vector3, persistent: no, deprecated name: vectorResult7

Vector result of expression h.

Is valid (resultValid8)

name: resultValid8, type: Bool, persistent: no

Indicates if the result of expression h is valid.

i1

name: i1, type: Integer, default: 0, deprecated name: intConstant0

Integer variable i1

i2

name: i2, type: Integer, default: 0, deprecated name: intConstant1

Integer variable i2

i3

name: i3, type: Integer, default: 0, deprecated name: intConstant2

Integer variable i3

i4

name: i4, type: Integer, default: 0, deprecated name: intConstant3

Integer variable i4

i5

name: i5, type: Integer, default: 0, deprecated name: intConstant4

Integer variable i5

i6

name: i6, type: Integer, default: 0, deprecated name: intConstant5

Integer variable i6

d1

name: d1, type: Double, default: 0, deprecated name: longDoubleConstant0,ld1

Double variable d1

d2

name: d2, type: Double, default: 0, deprecated name: longDoubleConstant1,ld2

Double variable d2

d3

name: d3, type: Double, default: 0, deprecated name: longDoubleConstant2,ld3

Double variable d3

d4

name: d4, type: Double, default: 0, deprecated name: longDoubleConstant3,ld4

Double variable d4

d5

name: d5, type: Double, default: 0, deprecated name: longDoubleConstant4,ld5

Double variable d5

d6

name: d6, type: Double, default: 0, deprecated name: longDoubleConstant5,ld6

Double variable d6

d7

name: d7, type: Double, default: 0, deprecated name: floatConstant0,f1

Double variable d7

d8

name: d8, type: Double, default: 0, deprecated name: floatConstant1,f2

Double variable d8

d9

name: d9, type: Double, default: 0, deprecated name: floatConstant2,f3

Double variable d9

d10

name: d10, type: Double, default: 0, deprecated name: floatConstant3,f4

Double variable d10

d11

name: d11, type: Double, default: 0, deprecated name: floatConstant4,f5

Double variable d11

d12

name: d12, type: Double, default: 0, deprecated name: floatConstant5,f6

Double variable d12

v1

name: v1, type: Vector3, default: 0 0 0, deprecated name: vectorConstant0

Vector variable v1

v2

name: v2, type: Vector3, default: 0 0 0, deprecated name: vectorConstant1

Vector variable v2

v3

name: v3, type: Vector3, default: 0 0 0, deprecated name: vectorConstant2

Vector variable v3

v4

name: v4, type: Vector3, default: 0 0 0, deprecated name: vectorConstant3

Vector variable v4

v5

name: v5, type: Vector3, default: 0 0 0, deprecated name: vectorConstant4

Vector variable v5

v6

name: v6, type: Vector3, default: 0 0 0, deprecated name: vectorConstant5

Vector variable v6

Handling on Domain Error

name: domainErrorHandling, type: Enum, default: Nothing

Values:

Title Name
Nothing Nothing
Error Message ErrorMessage

Apply Mode

name: applyMode, type: Enum, default: AutoApply, deprecated name: autoApply

If set to AutoClear, all results are cleared when any dependency field changes. If set to AutoApply, all results where a dependency has changed are updated. Dependency fields of a result are the expression field and the variable fields.

Values:

Title Name Deprecated Name
Auto Clear AutoClear Off,FALSE
Auto Apply AutoApply TRUE

Apply

name: apply, type: Trigger

Force calculation of all results with the current variables.

Comment (exp1Comment)

name: exp1Comment, type: String, deprecated name: expression0Comment

You can document the purpose of the expression here.

Comment (exp2Comment)

name: exp2Comment, type: String, deprecated name: expression1Comment

You can document the purpose of the expression here.

Comment (exp3Comment)

name: exp3Comment, type: String, deprecated name: expression2Comment

You can document the purpose of the expression here.

Comment (exp4Comment)

name: exp4Comment, type: String, deprecated name: expression3Comment

You can document the purpose of the expression here.

Comment (exp5Comment)

name: exp5Comment, type: String, deprecated name: expression4Comment

You can document the purpose of the expression here.

Comment (exp6Comment)

name: exp6Comment, type: String, deprecated name: expression5Comment

You can document the purpose of the expression here.

Comment (exp7Comment)

name: exp7Comment, type: String, deprecated name: expression6Comment

You can document the purpose of the expression here.

Comment (exp8Comment)

name: exp8Comment, type: String, deprecated name: expression7Comment

You can document the purpose of the expression here.

Comments (scalarVariablesComment)

name: scalarVariablesComment, type: String, deprecated name: scalarConstantsComment

You can document the purpose of the variables here. This can be useful when external fields are connected.

Comments (vectorVariablesComment)

name: vectorVariablesComment, type: String, deprecated name: vectorConstantsComment

You can document the purpose of the variables here. This can be useful when external fields are connected.

a.x:

name: resultVector1_x, type: Float, default: 0, deprecated name: vectorResult0\_x

X component of vector result a

a.y:

name: resultVector1_y, type: Float, default: 0, deprecated name: vectorResult0\_y

Y component of vector result a

a.z:

name: resultVector1_z, type: Float, default: 0, deprecated name: vectorResult0\_z

Y component of vector result a

b.x:

name: resultVector2_x, type: Float, default: 0, deprecated name: vectorResult1\_x

X component of vector result b

b.y:

name: resultVector2_y, type: Float, default: 0, deprecated name: vectorResult1\_y

Y component of vector result b

b.z:

name: resultVector2_z, type: Float, default: 0, deprecated name: vectorResult1\_z

Z component of vector result b

c.x:

name: resultVector3_x, type: Float, default: 0, deprecated name: vectorResult2\_x

X component of vector result c

c.y:

name: resultVector3_y, type: Float, default: 0, deprecated name: vectorResult2\_y

Y component of vector result c

c.z:

name: resultVector3_z, type: Float, default: 0, deprecated name: vectorResult2\_z

Z component of vector result c

d.x:

name: resultVector4_x, type: Float, default: 0, deprecated name: vectorResult3\_x

X component of vector result d

d.y:

name: resultVector4_y, type: Float, default: 0, deprecated name: vectorResult3\_y

Y component of vector result d

d.z:

name: resultVector4_z, type: Float, default: 0, deprecated name: vectorResult3\_z

Z component of vector result d

e.x:

name: resultVector5_x, type: Float, default: 0, deprecated name: vectorResult4\_x

X component of vector result e

e.y:

name: resultVector5_y, type: Float, default: 0, deprecated name: vectorResult4\_y

Y component of vector result e

e.z:

name: resultVector5_z, type: Float, default: 0, deprecated name: vectorResult4\_z

Z component of vector result e

f.x:

name: resultVector6_x, type: Float, default: 0, deprecated name: vectorResult5\_x

X component of vector result f

f.y:

name: resultVector6_y, type: Float, default: 0, deprecated name: vectorResult5\_y

Y component of vector result f

f.z:

name: resultVector6_z, type: Float, default: 0, deprecated name: vectorResult5\_z

Z component of vector result f

g.x:

name: resultVector7_x, type: Float, default: 0, deprecated name: vectorResult6\_x

X component of vector result g

g.y:

name: resultVector7_y, type: Float, default: 0, deprecated name: vectorResult6\_y

Y component of vector result g

g.z:

name: resultVector7_z, type: Float, default: 0, deprecated name: vectorResult6\_z

Z component of vector result g

h.x:

name: resultVector8_x, type: Float, default: 0, deprecated name: vectorResult7\_x

X component of vector result h

h.y:

name: resultVector8_y, type: Float, default: 0, deprecated name: vectorResult7\_y

Y component of vector result h

h.z:

name: resultVector8_z, type: Float, default: 0, deprecated name: vectorResult7\_z

Z component of vector result h

Hidden Fields

modeVector1

name: modeVector1, type: Bool, persistent: no, deprecated name: vecMode0,vecMode

modeVector2

name: modeVector2, type: Bool, persistent: no, deprecated name: vecMode1

modeVector3

name: modeVector3, type: Bool, persistent: no, deprecated name: vecMode2

modeVector4

name: modeVector4, type: Bool, persistent: no, deprecated name: vecMode3

modeVector5

name: modeVector5, type: Bool, persistent: no, deprecated name: vecMode4

modeVector6

name: modeVector6, type: Bool, persistent: no, deprecated name: vecMode5

modeVector7

name: modeVector7, type: Bool, persistent: no, deprecated name: vecMode6

modeVector8

name: modeVector8, type: Bool, persistent: no, deprecated name: vecMode7

clearScalarVariables

name: clearScalarVariables, type: Trigger, deprecated name: clearScalarConstants

clearVectorVariables

name: clearVectorVariables, type: Trigger, deprecated name: clearVectorConstants

clearExpressions

name: clearExpressions, type: Trigger