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

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

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

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.