Logical & Comparison Functions
Last updated
Last updated
CalcTree supports standard logical and comparison functions using and .
These functions return true
or false
, and are often used in conditional expressions and ternary operations (e.g. a > b ? "yes" : "no"
).
MathJS does not use a traditional if(...) {}
structure. Instead, native CalcTree parameters support conditional logic using the ternary operator:
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
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
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
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
Logical outputs (true
, false
) can be used in conditional formulas like:
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 . For a full list of available functions, visit the . Most functions listed there are supported in CalcTree unless otherwise noted.