#[non_exhaustive]pub struct UnitConversion {
pub numerator: f64,
pub denominator: f64,
pub decimal_exponent: i32,
pub offset: f64,
}Expand description
How a value in one unit becomes a value in another:
to = from * numerator / denominator * 10^decimal_exponent + offset.
The numerator and denominator are the two units’ mantissas, kept apart
so that a conversion to or from a unit whose mantissa is 1 (every SI
unit) rounds once: millimetres to inches divides by 254 instead of
multiplying by the rounded 1/254.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.numerator: f64The mantissa of the unit converted from.
denominator: f64The mantissa of the unit converted to.
decimal_exponent: i32The power of ten between the two units.
offset: f64Added after scaling; nonzero only to or from the SI
DEGREE_CELSIUS.
Implementations§
Source§impl UnitConversion
impl UnitConversion
Sourcepub fn apply(&self, value: f64) -> f64
pub fn apply(&self, value: f64) -> f64
Convert one value. A power of ten up to 10^22 is exact in f64, so
it is applied as one correctly rounded multiplication or division.
Sourcepub fn factor(&self) -> f64
pub fn factor(&self) -> f64
The multiplicative factor, numerator / denominator * 10^decimal_exponent.
Sourcepub fn powi(&self, exponent: i32) -> Option<Self>
pub fn powi(&self, exponent: i32) -> Option<Self>
The conversion raised to an integer power: the factor between the
squares (2) or cubes (3) of two units. None when the
conversion has an offset, which has no power.
Sourcepub fn is_identity(&self) -> bool
pub fn is_identity(&self) -> bool
Whether the conversion changes nothing.
Trait Implementations§
Source§impl Clone for UnitConversion
impl Clone for UnitConversion
Source§fn clone(&self) -> UnitConversion
fn clone(&self) -> UnitConversion
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more