Trait malachite_base::num::conversion::traits::SciMantissaAndExponent
source · [−]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
fn sci_mantissa_and_exponent(self) -> (M, E)
fn sci_mantissa_and_exponent(self) -> (M, E)
Extracts the scientific mantissa and exponent from a number.
fn from_sci_mantissa_and_exponent(sci_mantissa: M, sci_exponent: E) -> Option<T>
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
fn sci_mantissa(self) -> M
fn sci_mantissa(self) -> M
Extracts the scientific mantissa from a number.
fn sci_exponent(self) -> E
fn sci_exponent(self) -> E
Extracts the scientific exponent from a number.
Implementations on Foreign Types
sourceimpl SciMantissaAndExponent<f32, u64, u8> for u8
impl SciMantissaAndExponent<f32, u64, u8> for u8
sourcefn sci_mantissa_and_exponent(self) -> (f32, u64)
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_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.
sourcefn from_sci_mantissa_and_exponent(
sci_mantissa: f32,
sci_exponent: u64
) -> Option<u8>
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_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.
sourceimpl SciMantissaAndExponent<f64, u64, u8> for u8
impl SciMantissaAndExponent<f64, u64, u8> for u8
sourcefn sci_mantissa_and_exponent(self) -> (f64, u64)
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_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.
sourcefn from_sci_mantissa_and_exponent(
sci_mantissa: f64,
sci_exponent: u64
) -> Option<u8>
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_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.
sourceimpl SciMantissaAndExponent<f32, u64, u16> for u16
impl SciMantissaAndExponent<f32, u64, u16> for u16
sourcefn sci_mantissa_and_exponent(self) -> (f32, u64)
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_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.
sourcefn from_sci_mantissa_and_exponent(
sci_mantissa: f32,
sci_exponent: u64
) -> Option<u16>
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_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.
sourceimpl SciMantissaAndExponent<f64, u64, u16> for u16
impl SciMantissaAndExponent<f64, u64, u16> for u16
sourcefn sci_mantissa_and_exponent(self) -> (f64, u64)
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_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.
sourcefn from_sci_mantissa_and_exponent(
sci_mantissa: f64,
sci_exponent: u64
) -> Option<u16>
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_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.
sourceimpl SciMantissaAndExponent<f32, u64, u32> for u32
impl SciMantissaAndExponent<f32, u64, u32> for u32
sourcefn sci_mantissa_and_exponent(self) -> (f32, u64)
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_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.
sourcefn from_sci_mantissa_and_exponent(
sci_mantissa: f32,
sci_exponent: u64
) -> Option<u32>
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_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.
sourceimpl SciMantissaAndExponent<f64, u64, u32> for u32
impl SciMantissaAndExponent<f64, u64, u32> for u32
sourcefn sci_mantissa_and_exponent(self) -> (f64, u64)
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_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.
sourcefn from_sci_mantissa_and_exponent(
sci_mantissa: f64,
sci_exponent: u64
) -> Option<u32>
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_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.
sourceimpl SciMantissaAndExponent<f32, u64, u64> for u64
impl SciMantissaAndExponent<f32, u64, u64> for u64
sourcefn sci_mantissa_and_exponent(self) -> (f32, u64)
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_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.
sourcefn from_sci_mantissa_and_exponent(
sci_mantissa: f32,
sci_exponent: u64
) -> Option<u64>
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_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.
sourceimpl SciMantissaAndExponent<f64, u64, u64> for u64
impl SciMantissaAndExponent<f64, u64, u64> for u64
sourcefn sci_mantissa_and_exponent(self) -> (f64, u64)
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_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.
sourcefn from_sci_mantissa_and_exponent(
sci_mantissa: f64,
sci_exponent: u64
) -> Option<u64>
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_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.
sourceimpl SciMantissaAndExponent<f32, u64, u128> for u128
impl SciMantissaAndExponent<f32, u64, u128> for u128
sourcefn sci_mantissa_and_exponent(self) -> (f32, u64)
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_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.
sourcefn from_sci_mantissa_and_exponent(
sci_mantissa: f32,
sci_exponent: u64
) -> Option<u128>
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_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.
sourceimpl SciMantissaAndExponent<f64, u64, u128> for u128
impl SciMantissaAndExponent<f64, u64, u128> for u128
sourcefn sci_mantissa_and_exponent(self) -> (f64, u64)
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_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.
sourcefn from_sci_mantissa_and_exponent(
sci_mantissa: f64,
sci_exponent: u64
) -> Option<u128>
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_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.
sourceimpl SciMantissaAndExponent<f32, u64, usize> for usize
impl SciMantissaAndExponent<f32, u64, usize> for usize
sourcefn sci_mantissa_and_exponent(self) -> (f32, u64)
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_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.
sourcefn from_sci_mantissa_and_exponent(
sci_mantissa: f32,
sci_exponent: u64
) -> Option<usize>
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_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.
sourceimpl SciMantissaAndExponent<f64, u64, usize> for usize
impl SciMantissaAndExponent<f64, u64, usize> for usize
sourcefn sci_mantissa_and_exponent(self) -> (f64, u64)
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_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.
sourcefn from_sci_mantissa_and_exponent(
sci_mantissa: f64,
sci_exponent: u64
) -> Option<usize>
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_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.
sourceimpl SciMantissaAndExponent<f32, i64, f32> for f32
impl SciMantissaAndExponent<f32, i64, f32> for f32
sourcefn sci_mantissa_and_exponent(self) -> (f32, i64)
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.
sourcefn sci_mantissa(self) -> f32
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.
sourcefn sci_exponent(self) -> i64
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.
sourcefn from_sci_mantissa_and_exponent(
sci_mantissa: f32,
sci_exponent: i64
) -> Option<f32>
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.
sourceimpl SciMantissaAndExponent<f64, i64, f64> for f64
impl SciMantissaAndExponent<f64, i64, f64> for f64
sourcefn sci_mantissa_and_exponent(self) -> (f64, i64)
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.
sourcefn sci_mantissa(self) -> f64
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.
sourcefn sci_exponent(self) -> i64
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.
sourcefn from_sci_mantissa_and_exponent(
sci_mantissa: f64,
sci_exponent: i64
) -> Option<f64>
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.