pub enum Base {
B1000,
B1024,
}
Expand description
Represents the base for units Prefix.
Variants§
B1000
The most common base, where 1 k means 1000,
1 M means 1000^2
, …
B1024
A very common base for bibytes, where 1 kiB means 1024
, 1 MiB means
1024 * 1024
, …
Implementations§
Source§impl Base
impl Base
Sourcepub fn integral_exponent_for<F>(&self, x: F) -> i32
pub fn integral_exponent_for<F>(&self, x: F) -> i32
Using floor()
, returns the closest integer exponent to represent the
provided value x
in the self Base
.
The returned integer exponent is a multiple of 3 in order to match the prefixes’ exponents.
§Example
use si_scale::base::Base;
let x: f32 = 5.4e4;
let actual = Base::B1000.integral_exponent_for(x);
assert_eq!(actual, 3); // 1e3
let x: f64 = -5.4e-4;
let actual = Base::B1000.integral_exponent_for(x);
assert_eq!(actual, -6); // 1e-6
Sourcepub fn pow(&self, exponent: i32) -> f64
pub fn pow(&self, exponent: i32) -> f64
This helper function returns a f64
scaling factor for the mantissa,
obtained by raising self to the power of the provided exponent
divided by 3.
§Example
use si_scale::base::Base;
assert_eq!(Base::B1000.pow(9), 1e9);
assert_eq!(Base::B1024.pow(3), 1024f64)
Trait Implementations§
impl Eq for Base
impl StructuralPartialEq for Base
Auto Trait Implementations§
impl Freeze for Base
impl RefUnwindSafe for Base
impl Send for Base
impl Sync for Base
impl Unpin for Base
impl UnwindSafe for Base
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more