Units.NET was not designed for high-precision, but rather a tool of convenience and simplicity. As a result, there is usually a small error involved in both representing a value of a unit and converting between units. We are open to ideas how to improve this, while still keeping it simple and convenient.
- A base unit is chosen for all quantities
- SI base unit is preferred where available, such as
LengthUnit.MeterandVolumeUnit.CubicMeter. MassUnit.Gramwas chosen to better support SI prefixes likekilo,megaetc.
- SI base unit is preferred where available, such as
- The value is typically represented by a
doublevalue (64-bit) - Conversions go via the base unit.
- Centimeter => Meter => Kilometer
- As a result, most conversions have a rounding error. The error is larger for units that are way larger or way smaller than the base unit.
- A rounding error of
1e-5is accepted for round-trip conversion of most units in the library. In many use cases this is sufficient, but for others this may not be acceptable. - There is support for custom conversion functions between unit A to unit B, typically to add 3rd party units. This can also be used to improve the precision for specific conversions since it no longer converts via the base unit.
When adding test values for unit conversions:
- Use at least 7 significant figures where possible
- Beyond 16 significant digits is not useful due to
doubleprecision limits - Tests accept an error margin of
1e-5for most units