#[doc(hidden)] pub trait RawFloat:
Sized
+ Div<Output = Self>
+ Neg<Output = Self>
+ Mul<Output = Self>
+ Add<Output = Self>
+ LowerExp
+ PartialEq
+ PartialOrd
+ Default
+ Clone
+ Copy
+ Debug {
type Int: Integer + Into<u64>;
Show 22 associated constants and 6 methods
const INFINITY: Self;
const NEG_INFINITY: Self;
const NAN: Self;
const NEG_NAN: Self;
const BITS: u32;
const SIG_TOTAL_BITS: u32;
const EXP_MASK: Self::Int;
const SIG_MASK: Self::Int;
const MIN_EXPONENT_ROUND_TO_EVEN: i32;
const MAX_EXPONENT_ROUND_TO_EVEN: i32;
const SMALLEST_POWER_OF_TEN: i32;
const SIG_BITS: u32 = _;
const EXP_BITS: u32 = _;
const EXP_SAT: u32 = _;
const INFINITE_POWER: i32 = _;
const EXP_BIAS: u32 = _;
const EXP_MIN: i32 = _;
const LARGEST_POWER_OF_TEN: i32 = _;
const MAX_EXPONENT_FAST_PATH: i64 = _;
const MIN_EXPONENT_FAST_PATH: i64 = _;
const MAX_EXPONENT_DISGUISED_FAST_PATH: i64 = _;
const MAX_MANTISSA_FAST_PATH: u64 = _;
// Required methods
fn from_u64(v: u64) -> Self;
fn from_u64_bits(v: u64) -> Self;
fn pow10_fast_path(exponent: usize) -> Self;
fn classify(self) -> FpCategory;
fn to_bits(self) -> Self::Int;
// Provided method
fn integer_decode(self) -> (u64, i16, i8) { ... }
}
dec2flt
)Expand description
A helper trait to avoid duplicating basically all the conversion code for IEEE floats.
See the parent module’s doc comment for why this is necessary.
Should never ever be implemented for other types or be used outside the dec2flt
module.
Required Associated Constants§
const INFINITY: Self
dec2flt
)const NEG_INFINITY: Self
dec2flt
)const NAN: Self
dec2flt
)const NEG_NAN: Self
dec2flt
)Sourceconst SIG_TOTAL_BITS: u32
🔬This is a nightly-only experimental API. (dec2flt
)
const SIG_TOTAL_BITS: u32
dec2flt
)The number of bits in the significand, including the hidden bit.
const EXP_MASK: Self::Int
dec2flt
)const SIG_MASK: Self::Int
dec2flt
)Sourceconst MIN_EXPONENT_ROUND_TO_EVEN: i32
🔬This is a nightly-only experimental API. (dec2flt
)
const MIN_EXPONENT_ROUND_TO_EVEN: i32
dec2flt
)Round-to-even only happens for negative values of q when q ≥ −4 in the 64-bit case and when q ≥ −17 in the 32-bitcase.
When q ≥ 0,we have that 5^q ≤ 2m+1. In the 64-bit case,we have 5^q ≤ 2m+1 ≤ 2^54 or q ≤ 23. In the 32-bit case,we have 5^q ≤ 2m+1 ≤ 2^25 or q ≤ 10.
When q < 0, we have w ≥ (2m+1)×5^−q. We must have that w < 2^64 so (2m+1)×5^−q < 2^64. We have that 2m+1 > 2^53 (64-bit case) or 2m+1 > 2^24 (32-bit case). Hence,we must have 2^53×5^−q < 2^64 (64-bit) and 2^24×5^−q < 2^64 (32-bit). Hence we have 5^−q < 2^11 or q ≥ −4 (64-bit case) and 5^−q < 2^40 or q ≥ −17 (32-bitcase).
Thus we have that we only need to round ties to even when we have that q ∈ [−4,23](in the 64-bit case) or q∈[−17,10] (in the 32-bit case). In both cases,the power of five(5^|q|) fits in a 64-bit word.
const MAX_EXPONENT_ROUND_TO_EVEN: i32
dec2flt
)Sourceconst SMALLEST_POWER_OF_TEN: i32
🔬This is a nightly-only experimental API. (dec2flt
)
const SMALLEST_POWER_OF_TEN: i32
dec2flt
)Smallest decimal exponent for a non-zero value. This allows for fast pathing anything
smaller than 10^SMALLEST_POWER_OF_TEN
, which will round to zero.
The smallest power of ten is represented by ⌊log10(2^-n / (2^64 - 1))⌋
, where n
is
the smallest power of two. The 2^64 - 1)
denomenator comes from the number of values
that are representable by the intermediate storage format. I don’t actually know why
the storage format is relevant here.
The values may be calculated using the formula. Unfortunately we cannot calculate them at
compile time since intermediates exceed the range of an f64
.
Provided Associated Constants§
Sourceconst SIG_BITS: u32 = _
🔬This is a nightly-only experimental API. (dec2flt
)
const SIG_BITS: u32 = _
dec2flt
)The number of bits in the significand, excluding the hidden bit.
Sourceconst EXP_BITS: u32 = _
🔬This is a nightly-only experimental API. (dec2flt
)
const EXP_BITS: u32 = _
dec2flt
)Number of bits in the exponent.
Sourceconst EXP_SAT: u32 = _
🔬This is a nightly-only experimental API. (dec2flt
)
const EXP_SAT: u32 = _
dec2flt
)The saturated (maximum bitpattern) value of the exponent, i.e. the infinite representation.
This shifted fully right, use EXP_MASK
for the shifted value.
Sourceconst INFINITE_POWER: i32 = _
🔬This is a nightly-only experimental API. (dec2flt
)
const INFINITE_POWER: i32 = _
dec2flt
)Signed version of EXP_SAT
since we convert a lot.
Sourceconst EXP_BIAS: u32 = _
🔬This is a nightly-only experimental API. (dec2flt
)
const EXP_BIAS: u32 = _
dec2flt
)The exponent bias value. This is also the maximum value of the exponent.
Sourceconst EXP_MIN: i32 = _
🔬This is a nightly-only experimental API. (dec2flt
)
const EXP_MIN: i32 = _
dec2flt
)Minimum exponent value of normal values.
Sourceconst LARGEST_POWER_OF_TEN: i32 = _
🔬This is a nightly-only experimental API. (dec2flt
)
const LARGEST_POWER_OF_TEN: i32 = _
dec2flt
)Largest decimal exponent for a non-infinite value.
This is the max exponent in binary converted to the max exponent in decimal. Allows fast
pathing anything larger than 10^LARGEST_POWER_OF_TEN
, which will round to infinity.
Sourceconst MAX_EXPONENT_FAST_PATH: i64 = _
🔬This is a nightly-only experimental API. (dec2flt
)
const MAX_EXPONENT_FAST_PATH: i64 = _
dec2flt
)Maximum exponent for a fast path case, or ⌊(SIG_BITS+1)/log2(5)⌋
Sourceconst MIN_EXPONENT_FAST_PATH: i64 = _
🔬This is a nightly-only experimental API. (dec2flt
)
const MIN_EXPONENT_FAST_PATH: i64 = _
dec2flt
)Minimum exponent for a fast path case, or -⌊(SIG_BITS+1)/log2(5)⌋
Sourceconst MAX_EXPONENT_DISGUISED_FAST_PATH: i64 = _
🔬This is a nightly-only experimental API. (dec2flt
)
const MAX_EXPONENT_DISGUISED_FAST_PATH: i64 = _
dec2flt
)Maximum exponent that can be represented for a disguised-fast path case.
This is MAX_EXPONENT_FAST_PATH + ⌊(SIG_BITS+1)/log2(10)⌋
Sourceconst MAX_MANTISSA_FAST_PATH: u64 = _
🔬This is a nightly-only experimental API. (dec2flt
)
const MAX_MANTISSA_FAST_PATH: u64 = _
dec2flt
)Maximum mantissa for the fast-path (1 << 53
for f64).
Required Associated Types§
Required Methods§
Sourcefn from_u64(v: u64) -> Self
🔬This is a nightly-only experimental API. (dec2flt
)
fn from_u64(v: u64) -> Self
dec2flt
)Converts integer into float through an as cast. This is only called in the fast-path algorithm, and therefore will not lose precision, since the value will always have only if the value is <= Self::MAX_MANTISSA_FAST_PATH.
Sourcefn from_u64_bits(v: u64) -> Self
🔬This is a nightly-only experimental API. (dec2flt
)
fn from_u64_bits(v: u64) -> Self
dec2flt
)Performs a raw transmutation from an integer.
Sourcefn pow10_fast_path(exponent: usize) -> Self
🔬This is a nightly-only experimental API. (dec2flt
)
fn pow10_fast_path(exponent: usize) -> Self
dec2flt
)Gets a small power-of-ten for fast-path multiplication.
Sourcefn classify(self) -> FpCategory
🔬This is a nightly-only experimental API. (dec2flt
)
fn classify(self) -> FpCategory
dec2flt
)Returns the category that this number falls into.
Provided Methods§
Sourcefn integer_decode(self) -> (u64, i16, i8)
🔬This is a nightly-only experimental API. (dec2flt
)
fn integer_decode(self) -> (u64, i16, i8)
dec2flt
)Returns the mantissa, exponent and sign as integers.
That is, this returns (m, p, s)
such that s * m * 2^p
represents the original float.
For 0, the exponent will be -(EXP_BIAS + SIG_BITS
, which is the
minimum subnormal power.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.