pub trait SciMantissaAndExponent<M, E, T = Self>: Sized {
    fn sci_mantissa_and_exponent(self) -> (M, E);
    fn from_sci_mantissa_and_exponent(
        sci_mantissa: M,
        sci_exponent: E
    ) -> Option<T>; 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

Extracts the scientific mantissa and exponent from a number.

Constructs a number from its scientific mantissa and exponent.

Provided Methods

Extracts the scientific mantissa from a number.

Extracts the scientific exponent from a number.

Implementations on Foreign Types

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_with_rounding.

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.

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_with_rounding.

$$ 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.

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_with_rounding.

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.

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_with_rounding.

$$ 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.

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_with_rounding.

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.

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_with_rounding.

$$ 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.

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_with_rounding.

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.

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_with_rounding.

$$ 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.

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_with_rounding.

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.

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_with_rounding.

$$ 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.

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_with_rounding.

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.

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_with_rounding.

$$ 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.

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_with_rounding.

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.

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_with_rounding.

$$ 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.

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_with_rounding.

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.

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_with_rounding.

$$ 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.

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_with_rounding.

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.

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_with_rounding.

$$ 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.

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_with_rounding.

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.

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_with_rounding.

$$ 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.

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_with_rounding.

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.

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_with_rounding.

$$ 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.

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_with_rounding.

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.

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_with_rounding.

$$ 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.

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.

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.

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.

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.

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.

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.

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.

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.

Implementors