pub trait SciMantissaAndExponent<M, E, T = Self>: Sized {
    // Required methods
    fn sci_mantissa_and_exponent(self) -> (M, E);
    fn from_sci_mantissa_and_exponent(
        sci_mantissa: M,
        sci_exponent: E
    ) -> Option<T>;

    // Provided methods
    fn sci_mantissa(self) -> M { ... }
    fn sci_exponent(self) -> E { ... }
}
Expand description

Converts a number to or from a scientific mantissa and exponent.

See here for a definition of scientific mantissa and exponent.

Required Methods§

source

fn sci_mantissa_and_exponent(self) -> (M, E)

Extracts the scientific mantissa and exponent from a number.

source

fn from_sci_mantissa_and_exponent(sci_mantissa: M, sci_exponent: E) -> Option<T>

Constructs a number from its scientific mantissa and exponent.

Provided Methods§

source

fn sci_mantissa(self) -> M

Extracts the scientific mantissa from a number.

source

fn sci_exponent(self) -> E

Extracts the scientific exponent from a number.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl SciMantissaAndExponent<f32, i64> for f32

source§

fn sci_mantissa_and_exponent(self) -> (f32, i64)

Returns the scientific mantissa and exponent.

When $x$ is positive, nonzero, and finite, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. If $x$ is a valid float, the scientific mantissa $m_s$ is always exactly representable as a float of the same type. We have $$ f(x) = (\frac{x}{2^{\lfloor \log_2 x \rfloor}}, \lfloor \log_2 x \rfloor). $$

The inverse operation is from_sci_mantissa_and_exponent.

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if self is zero, infinite, or NaN.

§Examples

See here.

source§

fn sci_mantissa(self) -> f32

Returns the scientific mantissa.

When $x$ is positive, nonzero, and finite, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. If $x$ is a valid float, the scientific mantissa $m_s$ is always exactly representable as a float of the same type. We have $$ f(x) = \frac{x}{2^{\lfloor \log_2 x \rfloor}}. $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if self is zero, infinite, or NaN.

§Examples

See here.

source§

fn sci_exponent(self) -> i64

Returns the scientific exponent.

When $x$ is positive, nonzero, and finite, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. We have $$ f(x) = \lfloor \log_2 x \rfloor. $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if self is zero, infinite, or NaN.

§Examples

See here.

source§

fn from_sci_mantissa_and_exponent( sci_mantissa: f32, sci_exponent: i64 ) -> Option<f32>

Constructs a float from its scientific mantissa and exponent.

When $x$ is positive, nonzero, and finite, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$.

$$ f(x) = 2^{e_s}m_s, $$ or None if the result cannot be exactly represented as a float of the desired type (this happens if the exponent is too large or too small, if the mantissa is not in the range $[1, 2)$, or if the mantissa’s precision is too high for the exponent).

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if mantissa is zero, infinite, or NaN.

§Examples

See here.

source§

impl SciMantissaAndExponent<f32, u64> for u8

source§

fn sci_mantissa_and_exponent(self) -> (f32, u64)

Returns the scientific mantissa and exponent.

When $x$ is positive, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. We represent the rational mantissa as a float. The conversion might not be exact, so we round to the nearest float using the Nearest rounding mode. To use other rounding modes, use sci_mantissa_and_exponent_round.

If the result cannot be expressed as an integer of the specified type, None is returned. $$ f(x) \approx (\frac{x}{2^{\lfloor \log_2 x \rfloor}}, \lfloor \log_2 x \rfloor). $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if self is zero.

§Examples

See here.

source§

fn from_sci_mantissa_and_exponent( sci_mantissa: f32, sci_exponent: u64 ) -> Option<u8>

Constructs a primitive integer from its scientific mantissa and exponent.

When $x$ is positive, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. Here, the rational mantissa is provided as a float. If the mantissa is outside the range $[1, 2)$, None is returned.

Some combinations of mantissas and exponents do not specify an integer, in which case the resulting value is rounded to an integer using the Nearest rounding mode. To specify other rounding modes, use from_sci_mantissa_and_exponent_round.

$$ f(x) \approx 2^{e_s}m_s. $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if sci_mantissa is zero.

§Examples

See here.

source§

impl SciMantissaAndExponent<f32, u64> for u16

source§

fn sci_mantissa_and_exponent(self) -> (f32, u64)

Returns the scientific mantissa and exponent.

When $x$ is positive, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. We represent the rational mantissa as a float. The conversion might not be exact, so we round to the nearest float using the Nearest rounding mode. To use other rounding modes, use sci_mantissa_and_exponent_round.

If the result cannot be expressed as an integer of the specified type, None is returned. $$ f(x) \approx (\frac{x}{2^{\lfloor \log_2 x \rfloor}}, \lfloor \log_2 x \rfloor). $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if self is zero.

§Examples

See here.

source§

fn from_sci_mantissa_and_exponent( sci_mantissa: f32, sci_exponent: u64 ) -> Option<u16>

Constructs a primitive integer from its scientific mantissa and exponent.

When $x$ is positive, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. Here, the rational mantissa is provided as a float. If the mantissa is outside the range $[1, 2)$, None is returned.

Some combinations of mantissas and exponents do not specify an integer, in which case the resulting value is rounded to an integer using the Nearest rounding mode. To specify other rounding modes, use from_sci_mantissa_and_exponent_round.

$$ f(x) \approx 2^{e_s}m_s. $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if sci_mantissa is zero.

§Examples

See here.

source§

impl SciMantissaAndExponent<f32, u64> for u32

source§

fn sci_mantissa_and_exponent(self) -> (f32, u64)

Returns the scientific mantissa and exponent.

When $x$ is positive, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. We represent the rational mantissa as a float. The conversion might not be exact, so we round to the nearest float using the Nearest rounding mode. To use other rounding modes, use sci_mantissa_and_exponent_round.

If the result cannot be expressed as an integer of the specified type, None is returned. $$ f(x) \approx (\frac{x}{2^{\lfloor \log_2 x \rfloor}}, \lfloor \log_2 x \rfloor). $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if self is zero.

§Examples

See here.

source§

fn from_sci_mantissa_and_exponent( sci_mantissa: f32, sci_exponent: u64 ) -> Option<u32>

Constructs a primitive integer from its scientific mantissa and exponent.

When $x$ is positive, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. Here, the rational mantissa is provided as a float. If the mantissa is outside the range $[1, 2)$, None is returned.

Some combinations of mantissas and exponents do not specify an integer, in which case the resulting value is rounded to an integer using the Nearest rounding mode. To specify other rounding modes, use from_sci_mantissa_and_exponent_round.

$$ f(x) \approx 2^{e_s}m_s. $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if sci_mantissa is zero.

§Examples

See here.

source§

impl SciMantissaAndExponent<f32, u64> for u64

source§

fn sci_mantissa_and_exponent(self) -> (f32, u64)

Returns the scientific mantissa and exponent.

When $x$ is positive, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. We represent the rational mantissa as a float. The conversion might not be exact, so we round to the nearest float using the Nearest rounding mode. To use other rounding modes, use sci_mantissa_and_exponent_round.

If the result cannot be expressed as an integer of the specified type, None is returned. $$ f(x) \approx (\frac{x}{2^{\lfloor \log_2 x \rfloor}}, \lfloor \log_2 x \rfloor). $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if self is zero.

§Examples

See here.

source§

fn from_sci_mantissa_and_exponent( sci_mantissa: f32, sci_exponent: u64 ) -> Option<u64>

Constructs a primitive integer from its scientific mantissa and exponent.

When $x$ is positive, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. Here, the rational mantissa is provided as a float. If the mantissa is outside the range $[1, 2)$, None is returned.

Some combinations of mantissas and exponents do not specify an integer, in which case the resulting value is rounded to an integer using the Nearest rounding mode. To specify other rounding modes, use from_sci_mantissa_and_exponent_round.

$$ f(x) \approx 2^{e_s}m_s. $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if sci_mantissa is zero.

§Examples

See here.

source§

impl SciMantissaAndExponent<f32, u64> for u128

source§

fn sci_mantissa_and_exponent(self) -> (f32, u64)

Returns the scientific mantissa and exponent.

When $x$ is positive, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. We represent the rational mantissa as a float. The conversion might not be exact, so we round to the nearest float using the Nearest rounding mode. To use other rounding modes, use sci_mantissa_and_exponent_round.

If the result cannot be expressed as an integer of the specified type, None is returned. $$ f(x) \approx (\frac{x}{2^{\lfloor \log_2 x \rfloor}}, \lfloor \log_2 x \rfloor). $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if self is zero.

§Examples

See here.

source§

fn from_sci_mantissa_and_exponent( sci_mantissa: f32, sci_exponent: u64 ) -> Option<u128>

Constructs a primitive integer from its scientific mantissa and exponent.

When $x$ is positive, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. Here, the rational mantissa is provided as a float. If the mantissa is outside the range $[1, 2)$, None is returned.

Some combinations of mantissas and exponents do not specify an integer, in which case the resulting value is rounded to an integer using the Nearest rounding mode. To specify other rounding modes, use from_sci_mantissa_and_exponent_round.

$$ f(x) \approx 2^{e_s}m_s. $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if sci_mantissa is zero.

§Examples

See here.

source§

impl SciMantissaAndExponent<f32, u64> for usize

source§

fn sci_mantissa_and_exponent(self) -> (f32, u64)

Returns the scientific mantissa and exponent.

When $x$ is positive, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. We represent the rational mantissa as a float. The conversion might not be exact, so we round to the nearest float using the Nearest rounding mode. To use other rounding modes, use sci_mantissa_and_exponent_round.

If the result cannot be expressed as an integer of the specified type, None is returned. $$ f(x) \approx (\frac{x}{2^{\lfloor \log_2 x \rfloor}}, \lfloor \log_2 x \rfloor). $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if self is zero.

§Examples

See here.

source§

fn from_sci_mantissa_and_exponent( sci_mantissa: f32, sci_exponent: u64 ) -> Option<usize>

Constructs a primitive integer from its scientific mantissa and exponent.

When $x$ is positive, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. Here, the rational mantissa is provided as a float. If the mantissa is outside the range $[1, 2)$, None is returned.

Some combinations of mantissas and exponents do not specify an integer, in which case the resulting value is rounded to an integer using the Nearest rounding mode. To specify other rounding modes, use from_sci_mantissa_and_exponent_round.

$$ f(x) \approx 2^{e_s}m_s. $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if sci_mantissa is zero.

§Examples

See here.

source§

impl SciMantissaAndExponent<f64, i64> for f64

source§

fn sci_mantissa_and_exponent(self) -> (f64, i64)

Returns the scientific mantissa and exponent.

When $x$ is positive, nonzero, and finite, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. If $x$ is a valid float, the scientific mantissa $m_s$ is always exactly representable as a float of the same type. We have $$ f(x) = (\frac{x}{2^{\lfloor \log_2 x \rfloor}}, \lfloor \log_2 x \rfloor). $$

The inverse operation is from_sci_mantissa_and_exponent.

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if self is zero, infinite, or NaN.

§Examples

See here.

source§

fn sci_mantissa(self) -> f64

Returns the scientific mantissa.

When $x$ is positive, nonzero, and finite, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. If $x$ is a valid float, the scientific mantissa $m_s$ is always exactly representable as a float of the same type. We have $$ f(x) = \frac{x}{2^{\lfloor \log_2 x \rfloor}}. $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if self is zero, infinite, or NaN.

§Examples

See here.

source§

fn sci_exponent(self) -> i64

Returns the scientific exponent.

When $x$ is positive, nonzero, and finite, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. We have $$ f(x) = \lfloor \log_2 x \rfloor. $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if self is zero, infinite, or NaN.

§Examples

See here.

source§

fn from_sci_mantissa_and_exponent( sci_mantissa: f64, sci_exponent: i64 ) -> Option<f64>

Constructs a float from its scientific mantissa and exponent.

When $x$ is positive, nonzero, and finite, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$.

$$ f(x) = 2^{e_s}m_s, $$ or None if the result cannot be exactly represented as a float of the desired type (this happens if the exponent is too large or too small, if the mantissa is not in the range $[1, 2)$, or if the mantissa’s precision is too high for the exponent).

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if mantissa is zero, infinite, or NaN.

§Examples

See here.

source§

impl SciMantissaAndExponent<f64, u64> for u8

source§

fn sci_mantissa_and_exponent(self) -> (f64, u64)

Returns the scientific mantissa and exponent.

When $x$ is positive, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. We represent the rational mantissa as a float. The conversion might not be exact, so we round to the nearest float using the Nearest rounding mode. To use other rounding modes, use sci_mantissa_and_exponent_round.

If the result cannot be expressed as an integer of the specified type, None is returned. $$ f(x) \approx (\frac{x}{2^{\lfloor \log_2 x \rfloor}}, \lfloor \log_2 x \rfloor). $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if self is zero.

§Examples

See here.

source§

fn from_sci_mantissa_and_exponent( sci_mantissa: f64, sci_exponent: u64 ) -> Option<u8>

Constructs a primitive integer from its scientific mantissa and exponent.

When $x$ is positive, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. Here, the rational mantissa is provided as a float. If the mantissa is outside the range $[1, 2)$, None is returned.

Some combinations of mantissas and exponents do not specify an integer, in which case the resulting value is rounded to an integer using the Nearest rounding mode. To specify other rounding modes, use from_sci_mantissa_and_exponent_round.

$$ f(x) \approx 2^{e_s}m_s. $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if sci_mantissa is zero.

§Examples

See here.

source§

impl SciMantissaAndExponent<f64, u64> for u16

source§

fn sci_mantissa_and_exponent(self) -> (f64, u64)

Returns the scientific mantissa and exponent.

When $x$ is positive, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. We represent the rational mantissa as a float. The conversion might not be exact, so we round to the nearest float using the Nearest rounding mode. To use other rounding modes, use sci_mantissa_and_exponent_round.

If the result cannot be expressed as an integer of the specified type, None is returned. $$ f(x) \approx (\frac{x}{2^{\lfloor \log_2 x \rfloor}}, \lfloor \log_2 x \rfloor). $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if self is zero.

§Examples

See here.

source§

fn from_sci_mantissa_and_exponent( sci_mantissa: f64, sci_exponent: u64 ) -> Option<u16>

Constructs a primitive integer from its scientific mantissa and exponent.

When $x$ is positive, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. Here, the rational mantissa is provided as a float. If the mantissa is outside the range $[1, 2)$, None is returned.

Some combinations of mantissas and exponents do not specify an integer, in which case the resulting value is rounded to an integer using the Nearest rounding mode. To specify other rounding modes, use from_sci_mantissa_and_exponent_round.

$$ f(x) \approx 2^{e_s}m_s. $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if sci_mantissa is zero.

§Examples

See here.

source§

impl SciMantissaAndExponent<f64, u64> for u32

source§

fn sci_mantissa_and_exponent(self) -> (f64, u64)

Returns the scientific mantissa and exponent.

When $x$ is positive, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. We represent the rational mantissa as a float. The conversion might not be exact, so we round to the nearest float using the Nearest rounding mode. To use other rounding modes, use sci_mantissa_and_exponent_round.

If the result cannot be expressed as an integer of the specified type, None is returned. $$ f(x) \approx (\frac{x}{2^{\lfloor \log_2 x \rfloor}}, \lfloor \log_2 x \rfloor). $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if self is zero.

§Examples

See here.

source§

fn from_sci_mantissa_and_exponent( sci_mantissa: f64, sci_exponent: u64 ) -> Option<u32>

Constructs a primitive integer from its scientific mantissa and exponent.

When $x$ is positive, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. Here, the rational mantissa is provided as a float. If the mantissa is outside the range $[1, 2)$, None is returned.

Some combinations of mantissas and exponents do not specify an integer, in which case the resulting value is rounded to an integer using the Nearest rounding mode. To specify other rounding modes, use from_sci_mantissa_and_exponent_round.

$$ f(x) \approx 2^{e_s}m_s. $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if sci_mantissa is zero.

§Examples

See here.

source§

impl SciMantissaAndExponent<f64, u64> for u64

source§

fn sci_mantissa_and_exponent(self) -> (f64, u64)

Returns the scientific mantissa and exponent.

When $x$ is positive, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. We represent the rational mantissa as a float. The conversion might not be exact, so we round to the nearest float using the Nearest rounding mode. To use other rounding modes, use sci_mantissa_and_exponent_round.

If the result cannot be expressed as an integer of the specified type, None is returned. $$ f(x) \approx (\frac{x}{2^{\lfloor \log_2 x \rfloor}}, \lfloor \log_2 x \rfloor). $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if self is zero.

§Examples

See here.

source§

fn from_sci_mantissa_and_exponent( sci_mantissa: f64, sci_exponent: u64 ) -> Option<u64>

Constructs a primitive integer from its scientific mantissa and exponent.

When $x$ is positive, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. Here, the rational mantissa is provided as a float. If the mantissa is outside the range $[1, 2)$, None is returned.

Some combinations of mantissas and exponents do not specify an integer, in which case the resulting value is rounded to an integer using the Nearest rounding mode. To specify other rounding modes, use from_sci_mantissa_and_exponent_round.

$$ f(x) \approx 2^{e_s}m_s. $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if sci_mantissa is zero.

§Examples

See here.

source§

impl SciMantissaAndExponent<f64, u64> for u128

source§

fn sci_mantissa_and_exponent(self) -> (f64, u64)

Returns the scientific mantissa and exponent.

When $x$ is positive, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. We represent the rational mantissa as a float. The conversion might not be exact, so we round to the nearest float using the Nearest rounding mode. To use other rounding modes, use sci_mantissa_and_exponent_round.

If the result cannot be expressed as an integer of the specified type, None is returned. $$ f(x) \approx (\frac{x}{2^{\lfloor \log_2 x \rfloor}}, \lfloor \log_2 x \rfloor). $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if self is zero.

§Examples

See here.

source§

fn from_sci_mantissa_and_exponent( sci_mantissa: f64, sci_exponent: u64 ) -> Option<u128>

Constructs a primitive integer from its scientific mantissa and exponent.

When $x$ is positive, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. Here, the rational mantissa is provided as a float. If the mantissa is outside the range $[1, 2)$, None is returned.

Some combinations of mantissas and exponents do not specify an integer, in which case the resulting value is rounded to an integer using the Nearest rounding mode. To specify other rounding modes, use from_sci_mantissa_and_exponent_round.

$$ f(x) \approx 2^{e_s}m_s. $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if sci_mantissa is zero.

§Examples

See here.

source§

impl SciMantissaAndExponent<f64, u64> for usize

source§

fn sci_mantissa_and_exponent(self) -> (f64, u64)

Returns the scientific mantissa and exponent.

When $x$ is positive, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. We represent the rational mantissa as a float. The conversion might not be exact, so we round to the nearest float using the Nearest rounding mode. To use other rounding modes, use sci_mantissa_and_exponent_round.

If the result cannot be expressed as an integer of the specified type, None is returned. $$ f(x) \approx (\frac{x}{2^{\lfloor \log_2 x \rfloor}}, \lfloor \log_2 x \rfloor). $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if self is zero.

§Examples

See here.

source§

fn from_sci_mantissa_and_exponent( sci_mantissa: f64, sci_exponent: u64 ) -> Option<usize>

Constructs a primitive integer from its scientific mantissa and exponent.

When $x$ is positive, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. Here, the rational mantissa is provided as a float. If the mantissa is outside the range $[1, 2)$, None is returned.

Some combinations of mantissas and exponents do not specify an integer, in which case the resulting value is rounded to an integer using the Nearest rounding mode. To specify other rounding modes, use from_sci_mantissa_and_exponent_round.

$$ f(x) \approx 2^{e_s}m_s. $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if sci_mantissa is zero.

§Examples

See here.

Implementors§