Math Functions and Constants
- Updated2025-10-31
- 2 minute(s) read
Use standard math constants and functions, such as exponential and trigonometric functions, to perform mathematical computations in your code.
Exponential Functions
| Function | Parameter | Result Type | Definition |
|---|---|---|---|
| ln(x) | real64 x | real64 | Natural logarithm |
| log(x) | real64 x | real64 | Common logarithm |
| exp(x) | real64 x | real64 | Natural exponential function |
| pow(basis, exponent) | real64 base, real64 exponent | real64 | Power function |
| root(radicand, rootExponent) | real64 radicand, real64 root exponent | real64 | Root function |
Example: Exponential Functions
program
section globals
real64 x, n, result
endsection
result = ln(x) * root( n, 2 )
endprogram
Trigonometric Functions
| Function | Parameter | Result Type | Definition |
|---|---|---|---|
| sin(x) | real64 x | real64 | Sine of x |
| cos(x) | real64 x | real64 | Cosine of x |
| tan(x) | real64 x | real64 | Tangent of x |
| arcsin(x) | real64 x | real64 | Arc sine of x |
| arccos(x) | real64 x | real64 | Arc cosine of x |
| arctan(x) | real64 x | real64 | Arc tangent of x |
Example: Trigonometric Functions
program
section globals
real64 frequency, result
endsection
result = sin( 2 * PI * frequency )
endprogram
Other Functions
| Function | Parameter | Result Type | Definition |
|---|---|---|---|
| abs(x) | integer/floating point data types | integer/floating point data types | Absolute value of x. |
| sign(x) | integer/floating point data types | integer/floating point data types | Returns 1, -1, or 0 depending on whether x is positive, negative, or zero. |
Example: Other Functions
program
section globals
real64 absValue_real64, inValue_real64
int32 absValue_int32, inValue_int32
endsection
absValue_real64 = abs( inValue_real64 )
absValue_int32 = abs( inValue_int32 )
endprogram
Math Constants
| Function | Definition |
|---|---|
| PI | Ratio of the circumference of a circle to the diameter |
Example: PI
program real64 _diameter = 2.5 real64 circle = diameter * PI sys:logInfo( sys:ui, "area of circle: %.2f", circle ) endprogram