Calculator¶
-
MLModule
¶ genre Arithmetic
authors Lennart Tautz
,Ola Friman
package FMEstable/ReleaseMeVis
dll MLCalculator
definition MLCalculator.def see also Arithmetic0
,SoCalculator
,Arithmetic
,Arithmetic1
,Arithmetic2
,ComplexArithmetic1
,ComplexArithmetic2
keywords arithmetic
,expression
,evaluation
,calculator
,calculation
,operation
,mathematics
,logic
,log
,exp
,abs
,sin
,cos
,tan
,min
,max
,add
,subtract
,minus
,multiply
,divide
,scalar
,vector
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 | ||||
|
||||||
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 | - | ||||
|
||||||
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).
Parameter Fields¶
Field Index¶
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.
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.
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.
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.
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.
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.
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.
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.
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
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 |
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