pub trait RawMantissaAndExponent<M, E, T = Self>: Sized {
    fn raw_mantissa_and_exponent(self) -> (M, E);
    fn from_raw_mantissa_and_exponent(raw_mantissa: M, raw_exponent: E) -> T;

    fn raw_mantissa(self) -> M { ... }
    fn raw_exponent(self) -> E { ... }
}
Expand description

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

See here for a definition of raw mantissa and exponent.

Required Methods

Extracts the raw mantissa and exponent from a number.

Constructs a number from its raw mantissa and exponent.

Provided Methods

Extracts the raw mantissa from a number.

Extracts the raw exponent from a number.

Implementations on Foreign Types

Returns the raw mantissa and exponent.

The raw exponent and raw mantissa are the actual bit patterns used to represent the components of self. When self is nonzero and finite, the raw exponent $e_r$ is an integer in $[0, 2^E-2]$ and the raw mantissa $m_r$ is an integer in $[0, 2^M-1]$.

When self is nonzero and finite, $f(x) = (m_r, e_r)$, where $$ m_r = \begin{cases} 2^{M+2^{E-1}-2}|x| & \text{if} \quad |x| < 2^{2-2^{E-1},} \\ 2^M \left ( \frac{|x|}{2^{\lfloor \log_2 |x| \rfloor}}-1\right ) & \textrm{otherwise}, \end{cases} $$ and $$ e_r = \begin{cases} 0 & \text{if} \quad |x| < 2^{2-2^{E-1}} \\ \lfloor \log_2 |x| \rfloor + 2^{E-1} - 1 & \textrm{otherwise}. \end{cases} $$ and $M$ and $E$ are the mantissa width and exponent width, respectively.

For zeros, infinities, or NaN, refer to IEEE 754 or look at the examples below.

The inverse operation is Self::from_raw_mantissa_and_exponent.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Returns the raw mantissa.

The raw mantissa is the actual bit pattern used to represent the mantissa of self. When self is nonzero and finite, it is an integer in $[0, 2^M-1]$.

When self is nonzero and finite, $$ f(x) = \begin{cases} 2^{M+2^{E-1}-2}|x| & \text{if} \quad |x| < 2^{2-2^{E-1}}, \\ 2^M \left ( \frac{|x|}{2^{\lfloor \log_2 |x| \rfloor}}-1\right ) & \textrm{otherwise}, \end{cases} $$ where $M$ and $E$ are the mantissa width and exponent width, respectively.

For zeros, infinities, or NaN, refer to IEEE 754 or look at the examples below.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Returns the raw exponent.

The raw exponent is the actual bit pattern used to represent the exponent of self. When self is nonzero and finite, it is an integer in $[0, 2^E-2]$.

When self is nonzero and finite, $$ f(x) = \begin{cases} 0 & \text{if} \quad |x| < 2^{2-2^{E-1}}, \\ \lfloor \log_2 |x| \rfloor + 2^{E-1} - 1 & \textrm{otherwise}, \end{cases} $$ where $M$ and $E$ are the mantissa width and exponent width, respectively.

For zeros, infinities, or NaN, refer to IEEE 754 or look at the examples below.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Constructs a float from its raw mantissa and exponent.

The raw exponent and raw mantissa are the actual bit patterns used to represent the components of a float. When the float is nonzero and finite, the raw exponent $e_r$ is an integer in $[0, 2^E-2]$ and the raw mantissa $m_r$ is an integer in $[0, 2^M-1]$.

When the exponent is not 2^E-1, $$ f(m_r, e_r) = \begin{cases} 2^{2-2^{E-1}-M}m_r & \text{if} \quad e_r = 0, \\ 2^{e_r-2^{E-1}+1}(2^{-M}m_r+1) & \textrm{otherwise}, \end{cases} $$ where $M$ and $E$ are the mantissa width and exponent width, respectively.

For zeros, infinities, or NaN, refer to IEEE 754 or look at the examples below.

This function only outputs a single, canonical, NaN.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Returns the raw mantissa and exponent.

The raw exponent and raw mantissa are the actual bit patterns used to represent the components of self. When self is nonzero and finite, the raw exponent $e_r$ is an integer in $[0, 2^E-2]$ and the raw mantissa $m_r$ is an integer in $[0, 2^M-1]$.

When self is nonzero and finite, $f(x) = (m_r, e_r)$, where $$ m_r = \begin{cases} 2^{M+2^{E-1}-2}|x| & \text{if} \quad |x| < 2^{2-2^{E-1},} \\ 2^M \left ( \frac{|x|}{2^{\lfloor \log_2 |x| \rfloor}}-1\right ) & \textrm{otherwise}, \end{cases} $$ and $$ e_r = \begin{cases} 0 & \text{if} \quad |x| < 2^{2-2^{E-1}} \\ \lfloor \log_2 |x| \rfloor + 2^{E-1} - 1 & \textrm{otherwise}. \end{cases} $$ and $M$ and $E$ are the mantissa width and exponent width, respectively.

For zeros, infinities, or NaN, refer to IEEE 754 or look at the examples below.

The inverse operation is Self::from_raw_mantissa_and_exponent.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Returns the raw mantissa.

The raw mantissa is the actual bit pattern used to represent the mantissa of self. When self is nonzero and finite, it is an integer in $[0, 2^M-1]$.

When self is nonzero and finite, $$ f(x) = \begin{cases} 2^{M+2^{E-1}-2}|x| & \text{if} \quad |x| < 2^{2-2^{E-1}}, \\ 2^M \left ( \frac{|x|}{2^{\lfloor \log_2 |x| \rfloor}}-1\right ) & \textrm{otherwise}, \end{cases} $$ where $M$ and $E$ are the mantissa width and exponent width, respectively.

For zeros, infinities, or NaN, refer to IEEE 754 or look at the examples below.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Returns the raw exponent.

The raw exponent is the actual bit pattern used to represent the exponent of self. When self is nonzero and finite, it is an integer in $[0, 2^E-2]$.

When self is nonzero and finite, $$ f(x) = \begin{cases} 0 & \text{if} \quad |x| < 2^{2-2^{E-1}}, \\ \lfloor \log_2 |x| \rfloor + 2^{E-1} - 1 & \textrm{otherwise}, \end{cases} $$ where $M$ and $E$ are the mantissa width and exponent width, respectively.

For zeros, infinities, or NaN, refer to IEEE 754 or look at the examples below.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Constructs a float from its raw mantissa and exponent.

The raw exponent and raw mantissa are the actual bit patterns used to represent the components of a float. When the float is nonzero and finite, the raw exponent $e_r$ is an integer in $[0, 2^E-2]$ and the raw mantissa $m_r$ is an integer in $[0, 2^M-1]$.

When the exponent is not 2^E-1, $$ f(m_r, e_r) = \begin{cases} 2^{2-2^{E-1}-M}m_r & \text{if} \quad e_r = 0, \\ 2^{e_r-2^{E-1}+1}(2^{-M}m_r+1) & \textrm{otherwise}, \end{cases} $$ where $M$ and $E$ are the mantissa width and exponent width, respectively.

For zeros, infinities, or NaN, refer to IEEE 754 or look at the examples below.

This function only outputs a single, canonical, NaN.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Implementors