Formula field - all about Syntax and Operators

About to create your first Calculoid formula field? Have a look at this post to get acquainted with Calculoid syntax and operators.

Expression Syntax

The parser accepts a pretty basic grammar. Operators have the normal precidence — f(x,y,z) (function calls), ^ (exponentiation), *, /, and % (multiplication, division, and remainder), and finally +, -, and || (addition, subtraction, and string concatenation) — and bind from left to right (yes, even exponentiation… it’s simpler that way).

There’s also a “,” (comma) operator that concatenates values into an array. It’s mostly useful for passing arguments to functions, since it doesn't always behave like you would think with regards to multi-dimensional arrays. If the left value is an array, it pushes the right value onto the end of the array, otherwise, it creates a new array “[left, right]“. This makes it impossible to create an array with another array as it’s first element.

Inside the first argument of the if function can be used these operators to compare expressions:

== Equal

!= Not equal

> Greater than

>= Greater or equal than

< Less than

<= Less or equal than

and Logical AND operator

or Logical OR operator

Example of if function: if(1 and 2 <= 4, 2, 0) + 2 = 4

Function operators

The parser has several built-in “functions” that are actually operators. The only difference from an outside point of view, is that they cannot be called with multiple arguments and they are evaluated by the simplify method if their arguments are constant.

sin(x) Sine of x (x is in radians)

cos(x) Cosine of x (x is in radians)

tan(x) Tangent of x (x is… well, you know)

asin(x) Arc sine of x (in radians)

acos(x) Arc cosine of x (in radians)

atan(x) Arc tangent of x (in radians)

sqrt(x) Square root of x. Result is NaN (Not a Number) if x is negative.