Arithmetic Expressions
Apply the principles below when using expressions in floating point fields.
Syntax
Expressions in floating point fields may be built in any of the following ways:
-
Include simple arithmetic operators +, -, *, /,
%
and ^.Example
Adding to an existing value.Note: The
%
operator returns the remainder when the first number is divided by the second. For example,5%4
returns 1 because 5 = 1*4 + 1, and85%4
also returns 1 because 85 = 21*4 + 1. -
Include parentheses ( and ) for more detailed calculations.
Example
Adding to an existing value. -
Include references to other fields.
Example
Setting the Z value to the average of X and Y. -
Include references to fields from other rows.
Example
Adding the Distance value and From > X coordinate to calculate the To > X coordinate. -
Use library functions.
Example
Enter the above averaging expression as follows:See Function library, below, for a list of useful functions.
-
Enter this to include the field’s current value in the calculation.
Example
Square the current value.
Invalid expressions
If you enter an invalid expression, the field is shaded red and the expression remains so that you can correct it.
If you click OK or Apply with an invalid expression, an error message appears. Close the message and correct the error.
Function library
Below are some useful functions for building expressions.
Function | Description | Syntax |
---|---|---|
abs | Absolute value of x | abs(x)
|
avg | Average of all the inputs | avg(x,y,z,w,u,v)
|
ceil | Smallest integer that is greater than or equal to x. | ceil(x)
|
clamp | Clamp x in range between r0 and r1, where r0 < r1. | clamp(r0,x,r1)
|
exp | e to the power of x. | exp(x)
|
floor | Largest integer that is less than or equal to x. | floor(x)
|
log | Natural logarithm of x. | log(x)
|
max | Largest value of all the inputs. | max(x,y,z,w,u)
|
min | Smallest value of all the inputs. | min(x,y,z,w,u)
|
pow | x to the power of y. | pow(x,y)
|
root | nth-root of x. where n is a positive integer. | root(x,n)
|
round | Round x to the nearest integer. | round(x)
|
sqrt | Square root of x, where x >= 0. | sqrt(x)
|
sum | Sum of all the inputs. | sum(x,y,z,w,u,v,t)
|
acos | Arc cosine of x expressed in radians. Interval [-1,+1] | acos(x)
|
asin | Arc sine of x expressed in radians. Interval [-1,+1] | asin(x)
|
atan | Arc tangent of x expressed in radians. Interval [-1,+1] | atan(x)
|
cos | Cosine of x. | cos(x)
|
sin | Sine of x. | sin(x)
|
tan | Tangent of x. | tan(x)
|
deg2rad | Convert x from degrees to radians. | deg2rad(x)
|
rad2deg | Convert x from radians to degrees. | rad2deg(x)
|
pi | The constant, pi. | pi
|
and | Logical AND: True only if x and y are both true. | x and y
|
not | Logical NOT: Negate the logical sense of the input. | not x
not (x and y)
|
or | Logical OR: True if either x or y is true. | x or y
|
if | If x is true then return y else return z. | if (x, y, z)
|
if-else | If the condition is true, return z. If false, return w. | if (x > y) z; else w;
|
Note: This is not an exhaustive list.