Type Definition quantity::QuantityScalar
source · [−]Implementations
sourceimpl<U: Unit> QuantityScalar<U>
impl<U: Unit> QuantityScalar<U>
sourcepub fn powi(&self, i: i32) -> Self
pub fn powi(&self, i: i32) -> Self
Calculate the integer power of self.
Example
let x = 5.0 * METER;
assert_relative_eq!(x.powi(2), &(25.0 * METER * METER));
sourcepub fn sqrt(&self) -> Result<Self, QuantityError>
pub fn sqrt(&self) -> Result<Self, QuantityError>
Try to calculate the square root of self.
Example
let x = 25.0 * METER * METER;
assert_relative_eq!(x.sqrt()?, &(5.0 * METER));
assert!(METER.sqrt().is_err());
sourcepub fn cbrt(&self) -> Result<Self, QuantityError>
pub fn cbrt(&self) -> Result<Self, QuantityError>
Try to calculate the cubic root of self.
Example
let x = 125.0 * METER * METER * METER;
assert_relative_eq!(x.cbrt()?, &(5.0 * METER));
assert!(METER.cbrt().is_err());
sourcepub fn root(&self, i: i32) -> Result<Self, QuantityError>
pub fn root(&self, i: i32) -> Result<Self, QuantityError>
Try to calculate the integer root of self.
Example
let x = 625.0 * METER * METER * METER * METER;
assert_relative_eq!(x.root(4)?, &(5.0 * METER));
assert!(METER.root(4).is_err());
sourcepub fn max(&self, other: Self) -> Result<Self, QuantityError> where
U: PartialEq + Clone,
pub fn max(&self, other: Self) -> Result<Self, QuantityError> where
U: PartialEq + Clone,
Return the maximum of self
and other
if they have the same unit.
Example
let p1 = 110.0 * KILO * PASCAL;
let p2 = BAR;
assert_relative_eq!(p1.max(p2)?, &p1);
assert!(BAR.max(KELVIN).is_err());
sourcepub fn min(&self, other: Self) -> Result<Self, QuantityError> where
U: PartialEq + Clone,
pub fn min(&self, other: Self) -> Result<Self, QuantityError> where
U: PartialEq + Clone,
Return the minimum of self
and other
if they have the same unit.
Example
let p1 = 110.0 * KILO * PASCAL;
let p2 = BAR;
assert_relative_eq!(p1.min(p2)?, &p2);
assert!(BAR.min(KELVIN).is_err());
sourcepub fn abs(&self) -> Self where
U: Clone,
pub fn abs(&self) -> Self where
U: Clone,
Return the absolute value of self
.
Example
let t = -50.0 * KELVIN;
assert_relative_eq!(t.abs(), &(50.0 * KELVIN));
sourcepub fn signum(&self) -> f64
pub fn signum(&self) -> f64
Returns a number that represents the sign of self
.
1.0
if the number is positive,+0.0
orINFINITY
-1.0
if the number is negative,-0.0
orNEG_INFINITY
NAN
if the number isNAN
sourcepub fn is_sign_positive(&self) -> bool
pub fn is_sign_positive(&self) -> bool
Returns true
if self
has a positive sign, including +0.0
, NaN
s with
positive sign bit and positive infinity.
sourcepub fn is_sign_negative(&self) -> bool
pub fn is_sign_negative(&self) -> bool
Returns true
if self
has a negative sign, including -0.0
, NaN
s with
negative sign bit and negative infinity.