#units
5 posts tagged #units.
The unit travels with the value
Every codebase has a comment like 'speed in m/s' that stopped being true two refactors ago. mp-units plugs quantities into std::format so the unit is printed from the type, with format specs that address the number and the unit separately. Change the unit and the log line follows. Episode 5 of the mp-units series.
A new unit in one line
In 1958 MIT students measured the Harvard Bridge in the body lengths of Oliver Smoot: 364.4 smoots plus one ear. Teaching mp-units the smoot, symbol, exact conversion factor and all, takes one line, and conversions, printing, and derived quantities work immediately. Episode 4 of the mp-units series.
Points are not deltas
The temperature is 21 degrees and the temperature rose by 21 degrees are different quantities, and adding two of the first is meaningless. mp-units models this with the affine space: quantity_point for absolute readings, quantity for changes, and the nonsense operations do not compile. Episode 3 of the mp-units series.
One per second is not one per second
Frequency (Hz), radioactivity (Bq), and angular velocity (rad/s) all share the dimension 1/s, so a dimensions-only units library happily adds a monitor's refresh rate to a radiation reading. mp-units pioneered quantity kinds: same dimension, different meaning, and mixing them does not compile. Episode 2 of the mp-units series.
The unit bug that crashed into Mars
In 1999 the Mars Climate Orbiter was lost because one team's software spoke pound-force seconds and another's expected newton seconds. mp-units, a C++ quantities library, makes that whole bug class uncompilable. First post of a series that follows the library to its C++29 standardization bid.