Expressions

Expressions used in Data Arithmetic module, grain quantity formulas and in graph function fitting have syntax similar to common programming languages.

All numbers are real (floating point), number literals use standard notation. Examples of valid numbers: 1, .707, 2.661, 8.2e-34.

Function, constant, and variable names start with a letter and continue with zero or more letters, numbers, or underscores. Examples of valid identifiers: pow10 (a function), Pi (a constant), d2_2 (a variable).

The precedence of operations is summarized in following table.

OperationAssociativityExamples
parenthesesN.A.(x)
function call and unary operatorsright to left-sqrt 3
power operatorright to left2^16
multiplication, division, and modulo operatorsleft to right9/2 * 8
addition and subtraction operatorsleft to right3 - 4 + 5

Note -3^2 is 9, that is (-3)^2, like in bc, but unlike in Perl or Python.

Available operators and functions are listed in following table.

OperatorMeaning
+ (unary)no op
- (unary)negative value
~negative value (equivalent to -)
+ (binary)addition
- (binary)subtraction
*multiplication
/division
%floating point modulo
^power
absabsolute value
floorrounding down to nearest integer
ceilrounding up to nearest integer
sqrtsquare root
cbrtcubic root
sinsine function
coscosine function
tantangent function
asinarc sine function
acosarc cosine function
atanarc tangent function
expbase-e exponential function
lnbase-e logarithm function
logbase-e logarithm function
pow10base-10 exponential function
log10base-10 logarithm function
sinhhyperbolic sine function
coshhyperbolic cosine function
tanhhyperbolic tangent function
asinhinverse hyperbolic sine function
acoshinverse hyperbolic cosine function
atanhinverse hyperbolic tangent function
powpower function, pow(x,y) equals to x^y
minminimum of two values
maxmaximum of two values
modfloating point modulo, mod(x,y) equals to x % y
hypotEuclidean distance function, hypot(x,y) equals to sqrt(x^2+y^2)
atan2arc tangent function of two variables

Beside that, there are a few peculiarities that may make typing simple expression easier:

If in doubt, write out expressions in full form.