-
Notifications
You must be signed in to change notification settings - Fork 383
Precision
Andreas Gullberg Larsen edited this page Nov 29, 2020
·
3 revisions
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.Meter
andVolumeUnit.CubicMeter
. -
MassUnit.Gram
was chosen to better support SI prefixes likekilo
,mega
etc.
- SI base unit is preferred where available, such as
- The value is typically represented by a
double
value (64-bit)- A few quantities use
decimal
due to having both very large and very small units: Power, Information and BitRate.
- A few quantities use
- Conversions go via the base unit.
- Centimeter => Meter => Kilometer
- As a result, most conversions has 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-5
is 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.