pub fn new_with<F, C>(x: F, base: Base, prefix_constraint: C) -> Self
    where
        F: Into<f64>,
        C: AsRef<Constraint>,
    {
        let x: f64 = x.into();

        // Closest integral exponent (multiple of 3)
        let exponent: i32 = base.integral_exponent_for(x);
        // Clamp the exponent using the constraint on prefix
        // let prefix = prefix_constraint.closest_prefix_below(exponent);
        let prefix = Self::closest_prefix_for(exponent, prefix_constraint);

        let mantissa = x / base.pow(prefix.exponent());

        Value {
            mantissa,
            base,
            prefix,
        }
    }
/// Returns a `Value` for the provided base.
///
/// # Example
///
/// ```
/// use si_scale::prelude::{Constraint, Base, Prefix, Value};
///
/// // 4 MiB
/// let actual = Value::new_with(4 * 1024 * 1024, Base::B1024, Constraint::None);
/// let expected = Value {
///     mantissa: 4f64,
///     prefix: Prefix::Mega,
///     base: Base::B1024,
/// };
/// assert_eq!(actual, expected);
/// ```
///
Returns a `Value` for the provided base.
Returns a ` Value ` for the provided base .
pub fn new_with<F, C>(x: F, base: Base, prefix_constraint: C) -> Self
    where
        F: Into<f64>,
        C: AsRef<Constraint>,
    {
        let x: f64 = x.into();
        // Closest integral exponent (multiple of 3)
        let exponent: i32 = base.integral_exponent_for(x);
        // Clamp the exponent using the constraint on prefix
        // let prefix = prefix_constraint.closest_prefix_below(exponent);
        let prefix = Self::closest_prefix_for(exponent, prefix_constraint);
        let mantissa = x / base.pow(prefix.exponent());
        Value {
            mantissa,
            base,
            prefix,
        }
    }
pub fn new_with < F , C > ( x : F , base : Base , prefix_constraint : C ) -> Self where F : Into < f64 > , C : AsRef < Constraint > , { let x : f64 = x . into ( ) ; // Closest integral exponent (multiple of 3) let exponent : i32 = base . integral_exponent_for ( x ) ; // Clamp the exponent using the constraint on prefix // let prefix = prefix_constraint.closest_prefix_below(exponent); let prefix = Self :: closest_prefix_for ( exponent , prefix_constraint ) ; let mantissa = x / base . pow ( prefix . exponent ( ) ) ; Value { mantissa , base , prefix , } }
Returns a `Value` for the provided base.
Returns a ` Value ` for the provided base .
x
F
base
Base
prefix_constraint
C
example
```
use si_scale::prelude::{Constraint, Base, Prefix, Value}.

4 MiB
let actual = Value::new_with(4 * 1024 * 1024, Base::B1024, Constraint::None);
let expected = Value {
mantissa: 4f64,
prefix: Prefix::Mega,
base: Base::B1024,
};
assert_eq!(actual, expected);
```
` ` ` use si_scale :: prelude :: { Constraint Base Prefix Value } . 4 MiB let actual = Value :: new_with ( 4 * 1024 * 1024 Base :: B1024 Constraint :: None ) ; let expected = Value { mantissa : 4f64 prefix : Prefix :: Mega base : Base :: B1024 } ; assert_eq! ( actual expected ) ; ` ` `