#[doc(hidden)]pub trait Float:
Sized
+ Div<Output = Self>
+ Neg<Output = Self>
+ Mul<Output = Self>
+ Add<Output = Self>
+ Debug
+ PartialEq
+ PartialOrd
+ Default
+ Clone
+ Copy {
type Int: Int + Into<u64>;
Show 18 associated constants and 2 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 = _;
// Required methods
fn classify(self) -> FpCategory;
fn to_bits(self) -> Self::Int;
}num_internals)Expand description
A helper trait to avoid duplicating basically all the conversion code for IEEE floats.
Required Associated Constants§
const INFINITY: Self
num_internals)const NEG_INFINITY: Self
num_internals)const NAN: Self
num_internals)const NEG_NAN: Self
num_internals)Sourceconst BITS: u32
🔬This is a nightly-only experimental API. (num_internals)
const BITS: u32
num_internals)Bit width of the float
Sourceconst SIG_TOTAL_BITS: u32
🔬This is a nightly-only experimental API. (num_internals)
const SIG_TOTAL_BITS: u32
num_internals)The number of bits in the significand, including the hidden bit.
const EXP_MASK: Self::Int
num_internals)const SIG_MASK: Self::Int
num_internals)Sourceconst MIN_EXPONENT_ROUND_TO_EVEN: i32
🔬This is a nightly-only experimental API. (num_internals)
const MIN_EXPONENT_ROUND_TO_EVEN: i32
num_internals)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-bit case.
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-bit case).
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
num_internals)Sourceconst SMALLEST_POWER_OF_TEN: i32
🔬This is a nightly-only experimental API. (num_internals)
const SMALLEST_POWER_OF_TEN: i32
num_internals)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) denominator 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. (num_internals)
const SIG_BITS: u32 = _
num_internals)The number of bits in the significand, excluding the hidden bit.
Sourceconst EXP_BITS: u32 = _
🔬This is a nightly-only experimental API. (num_internals)
const EXP_BITS: u32 = _
num_internals)Number of bits in the exponent.
Sourceconst EXP_SAT: u32 = _
🔬This is a nightly-only experimental API. (num_internals)
const EXP_SAT: u32 = _
num_internals)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. (num_internals)
const INFINITE_POWER: i32 = _
num_internals)Signed version of EXP_SAT since we convert a lot.
Sourceconst EXP_BIAS: u32 = _
🔬This is a nightly-only experimental API. (num_internals)
const EXP_BIAS: u32 = _
num_internals)The exponent bias value. This is also the maximum value of the exponent.
Sourceconst EXP_MIN: i32 = _
🔬This is a nightly-only experimental API. (num_internals)
const EXP_MIN: i32 = _
num_internals)Minimum exponent value of normal values.
Sourceconst LARGEST_POWER_OF_TEN: i32 = _
🔬This is a nightly-only experimental API. (num_internals)
const LARGEST_POWER_OF_TEN: i32 = _
num_internals)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.
Required Associated Types§
Required Methods§
Sourcefn classify(self) -> FpCategory
🔬This is a nightly-only experimental API. (num_internals)
fn classify(self) -> FpCategory
num_internals)Returns the category that this number falls into.
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.
Implementors§
Source§impl Float for f16
Available on target_has_reliable_f16 only.
impl Float for f16
target_has_reliable_f16 only.