Skip to main content
The unit model makes sensor values readable by people and convertible by software, including linear, non-linear, derived, and compound units.

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

  1. Look up both units and verify that their reduced dimensions/categories are compatible.
  2. Apply any source prefix before evaluating unit operations.
  3. Push the source value on the stack and evaluate its RPN operations top-to-bottom to reach the reference unit.
  4. Evaluate the target operations in reverse, using the inverse of each operation, to leave the reference unit.
  5. Apply a suitable target prefix and rounding policy.
The operation set includes constants and reversible arithmetic such as number, π, add, subtract, multiply, divide, power, logarithm, and negation. An implementation must reject an invalid stack program, a non-invertible conversion, or incompatible dimensions.

Compound units

Reduce each factor recursively into a numeric multiplier and base-unit exponent map. Compatible compound units have the same normalized exponent map.
Do not compare display strings to test compatibility. Normalize definitions and dimensions instead.

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.