Functions Reference

Built-in math, rounding, and trigonometric functions.

The formula engine includes a comprehensive set of built-in functions for mathematical operations.

Math Functions

abs(x)          Absolute value       abs(-5) = 5
ceil(x)         Round up             ceil(4.2) = 5
ceiling(x)      Round up (alias)     ceiling(4.2) = 5
floor(x)        Round down           floor(4.8) = 4
round(x)        Round to nearest     round(4.5) = 5
round(x; n)     Round to n decimals  round(3.456; 2) = 3.46
truncate(x; n)  Cut to n decimals    truncate(3.456; 2) = 3.45
min(a; b; ...)  Minimum              min(3; 1; 4) = 1
max(a; b; ...)  Maximum              max(3; 1; 4) = 4
sqrt(x)         Square root          sqrt(16) = 4
pow(x; n)       Power                pow(2; 3) = 8
log(x)          Natural logarithm    log(e) = 1
log10(x)        Base-10 logarithm    log10(100) = 2
exp(x)          Exponential          exp(1) = 2.718...

Conditions and comparison:
If(condition; ifTrue; ifFalse)     Choose by a condition              If(5 > 3; 10; 20) = 10
Case(cond1; value1; ...; default)  Value of the first true condition  Case(2 > 3; 10; 2 > 1; 20; 0) = 20
Equal(a; b)                        Equal (numbers or text)            Equal("steel"; "steel") = 1
Unequal(a; b)                      Not equal (numbers or text)        Unequal("steel"; "wood") = 1

Logical operators:
a and b  Both conditions are true        1 and 0 = 0
a or b   At least one condition is true  1 or 0 = 1
not a    Negation                        not 0 = 1

Text:
len(text)          Text length            len("hello") = 5
text(value)        Number to text         text(42) = "42"
number(text)       Text to number         number("42") = 42
concat(a; b; ...)  Join texts             concat("hi"; " "; "there") = "hi there"
join(sep; a; ...)  Join with a separator  join("-"; "a"; "b"; "c") = "a-b-c"

Trigonometric Functions

All trigonometric functions work in radians. To convert degrees to radians, multiply by π/180.

sin(x)       Sine (radians)                      sin(0) = 0
cos(x)       Cosine                              cos(0) = 1
tan(x)       Tangent                             tan(0) = 0
asin(x)      Arc sine                            asin(1) = π/2
acos(x)      Arc cosine                          acos(1) = 0
atan(x)      Arc tangent                         atan(1) = π/4
atan2(y; x)  Angle of a point (y first, then x)  atan2(1; 1) = π/4

Rounding Functions

  • ceil(x) / ceiling(x) — always rounds up: ceil(4.1) = 5. Use for quantities that must be whole.
  • floor(x) — always rounds down: floor(4.9) = 4.
  • round(x) — rounds to nearest integer: round(4.5) = 5.
  • round(x; n) — rounds to n decimal places: round(3.14159; 2) = 3.14.
  • truncate(x; n) — truncates to n decimal places (no rounding): truncate(3.14159; 2) = 3.14.

Logarithmic Functions

  • log(x) — natural logarithm (base e): log(e) = 1.
  • log10(x) — base-10 logarithm: log10(100) = 2.

Conditions and Comparison

  • If(condition; valueIfTrue; valueIfFalse) — returns one of two values: If(5 > 3; 10; 20) = 10.
  • Case(condition1; value1; ...; default) — returns the value of the first true condition: Case(2 > 3; 10; 2 > 1; 20; 0) = 20. Each condition is a comparison.
  • Equal(a; b) — 1 when the values are equal, including text: Equal("steel"; "steel") = 1. Same as a == b.
  • Unequal(a; b) — 1 when the values differ: Unequal("steel"; "wood") = 1. Same as a != b.

Logical Operators

  • a and b — 1 when both conditions are true: If($width > 1000 and $height > 2000; 1; 0).
  • a or b — 1 when at least one condition is true: If($width > 3000 or $height > 3000; 1; 0).
  • not a — negation: If(not ($width > 1000); 1; 0).

Text Functions

  • len(text) — returns the length of a string: len("hello") = 5.
  • text(value) — converts a number to text: text(42) = "42".
  • number(text) — converts text to a number: number("42") = 42.
  • concat(a; b; ...) — concatenates strings: concat("width: "; text($width)) = "width: 1000".
  • join(separator; val1; val2; ...) — joins values with a separator: join("; "; "a"; "b"; "c") = "a; b; c".

Use ceil() for material quantities — you can't buy half a panel, so always round up.