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_falseExample: Basic if logic
result = load > limit ? "Fail" : "Pass"Nested conditions (like else if)
check = ratio < 1 ? "OK" : ratio < 1.5 ? "Warning" : "Fail"Comparison Functions
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
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
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
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:For multi-value comparisons (e.g. arrays), use
deepEqual()instead ofequal().Comparisons between unit-bearing quantities must be dimensionally consistent (e.g.
2 m > 1 mis valid,2 m > 1 kgis not).
Last updated