Logical & Comparison Functions

CalcTree supports standard logical and comparison functions using MathJS syntax and comparison operators.

These functions return true or false, and are often used in conditional expressions and ternary operations (e.g. a > b ? "yes" : "no").

If Statements

MathJS does not use a traditional if(...) {} structure. Instead, native CalcTree parameters support conditional logic using the ternary operator:

condition ? value_if_true : value_if_false

Example: Basic if logic

result = load > limit ? "Fail" : "Pass"

Nested conditions (like else if)

check = ratio < 1 ? "OK" : ratio < 1.5 ? "Warning" : "Fail"

Comparison Functions

Function
Description
CalcTree Example

equal(a, b)

Checks strict equality

equal(2, 2) β†’ true

unequal(a, b)

Checks inequality

unequal(2, 3) β†’ true

smaller(a, b)

Less than

smaller(1, 2) β†’ true

smallerEq(a, b)

Less than or equal

smallerEq(2, 2) β†’ true

larger(a, b)

Greater than

larger(3, 1) β†’ true

largerEq(a, b)

Greater than or equal

largerEq(3, 3) β†’ true

Natural and String Comparison

Function
Description
CalcTree Example

compare(a, b)

General numerical comparison

compare(2, 3) β†’ -1

compareText(a, b)

Lexical string comparison

compareText("a", "b") β†’ -1

compareNatural(a, b)

Natural-order comparison (e.g., v1 < v2)

compareNatural("2", "10") β†’ -1

Deep & Elementwise Equality

Function
Description
CalcTree Example

deepEqual(a, b)

Element-wise equality for arrays/matrices

deepEqual([1, 2], [1, 2]) β†’ true

equalText(a, b)

Text string equality

equalText("abc", "abc") β†’ true

Logical Functions

Function
Description
CalcTree Example

and(a, b)

Logical AND

and(true, true) β†’ true

or(a, b)

Logical OR

or(false, true) β†’ true

not(a)

Logical NOT

not(true) β†’ false

xor(a, b)

Exclusive OR

xor(true, false) β†’ true

Notes for CalcTree

  • Logical outputs (true, false) can be used in conditional formulas like:

    result = load > limit ? "Fail" : "Pass"
  • For multi-value comparisons (e.g. arrays), use deepEqual() instead of equal().

  • Comparisons between unit-bearing quantities must be dimensionally consistent (e.g. 2 m > 1 m is valid, 2 m > 1 kg is not).

πŸ“˜ Looking for more functions? CalcTree’s expression engine is powered by MathJS. For a full list of available functions, visit the MathJS Function Reference. Most functions listed there are supported in CalcTree unless otherwise noted.

Last updated