RiX walkthrough · 8c
Physical units and quantities
Compose units as values, convert exactly, and catch dimensional mistakes.
Units are ordinary values
RiX loads its standard units into the .Units map. A unit can be retrieved, assigned, passed around, multiplied, or divided like another value:
The result is 12~[m/s]. Internally RiX keeps an exact magnitude, a physical dimension vector, and a display unit.
Concise scientific notation
The bracket form is lookup-and-multiply sugar over the same .Units values:
Unknown names inside ~[...] are errors rather than silently becoming labels.
Compatible addition
Compatible quantities are normalized before arithmetic. Addition preserves the left operand's display unit:
The values describe the same duration but display as 150~[s] and 2..1/2~[min]. Trying 1~[m] + 1~[s] raises a dimensional error.
Explicit conversion
The quantity already knows its source unit, so conversion only needs a target:
Target strings are also accepted: .ConvertUnit(speed, "m/s").
Affine temperature coordinates
Units double as one-argument constructors. This matters for Celsius and Fahrenheit because their zero points differ:
Subtracting two temperature points produces a linear difference:
Adding two temperature points or compounding an affine coordinate is rejected.
Extend the active collection
.DefineUnit returns a unit value. Put it in an ordinary map overlay named Units; the sugar checks that lexical map before the system default:
Next
The next lesson uses the parallel .Exact collection for π, i, and algebraic generators. Physical units and exact symbolic magnitudes can be composed.