Model
A unit category groups compatible units representing the same measurable quantity. It has exactly one reference unit—normally an SI unit or a unit with a derivation to SI. A regular unit defines reversible Reverse Polish Notation (RPN) operations that map its value to the category reference unit. A compound unit is a numeric factor multiplied by unit factors raised to integer exponents. Units without conversion operations are equivalent to their category reference unit.Conversion algorithm
- Look up both units and verify that their reduced dimensions/categories are compatible.
- Apply any source prefix before evaluating unit operations.
- Push the source value on the stack and evaluate its RPN operations top-to-bottom to reach the reference unit.
- Evaluate the target operations in reverse, using the inverse of each operation, to leave the reference unit.
- Apply a suitable target prefix and rounding policy.
Compound units
Reduce each factor recursively into a numeric multiplier and base-unit exponent map. Compatible compound units have the same normalized exponent map.Sensor implementation rules
- Send a stable unit symbol with every quantity field for which magnitude depends on a unit.
- Preserve significant digits and quality metadata during conversion.
- Keep raw readings when a converted value will be used for audit or billing.
- Accept an unknown unit as a value you can display or store, but do not invent a conversion.
- Reject incompatible control inputs before changing device state.