Writing scalars
Behavior
- Scalars combine with other scalars under the usual arithmetic.
- A scalar applied to a table operates on every cell:
[10; 20; 30] * 1.1. - A scalar combined with a unit number scales it:
3 * 5mis a length.
Booleans
TrueMath has no separate boolean type —true and false are named scalar constants equal to 1 and 0. They are interchangeable with the numbers, so you can write whichever reads best:
1 or 0) and expect one in a condition. Boolean flag arguments — such as descending in sort or beginning_of_period in the finance functions — accept true/false or 1/0.
Equality is exact: because true is 1, 1 == true is true but 2 == true is false.
Deep details: how a condition treats other numbers
Deep details: how a condition treats other numbers
Inside
if, &&, ||, and !, the condition must reduce to a scalar. Comparing unit values is fine — 3 m < 5 m yields the scalar 1 — but a bare unit value as the condition (if(5 m; …)) raises an error. A scalar counts as true when its absolute value is at least 0.5, and false otherwise — roughly, “rounds to a nonzero number.” So if(2; …) takes the true branch (even though 2 != true), if(0.4; …) takes the false branch, and if(-1; …) is true. In normal use you pass true/false, 1/0, or a comparison result, where this never comes up.
