Trait minimal_lexical::Float
source · pub trait Float: Sized + Copy + PartialEq + PartialOrd + Send + Sync + Add<Output = Self> + AddAssign + Div<Output = Self> + DivAssign + Mul<Output = Self> + MulAssign + Rem<Output = Self> + RemAssign + Sub<Output = Self> + SubAssign + Neg<Output = Self> {
Show 21 associated constants and 8 methods
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
// Required methods
;
;
;
;
// Provided methods
{ ... }
{ ... }
{ ... }
{ ... }
}
Expand description
Generic floating-point type, to be used in generic code for parsing.
Although the trait is part of the public API, the trait provides methods and constants that are effectively non-public: they may be removed at any time without any breaking changes.
Required Associated Constants§
source
Maximum number of digits that can contribute in the mantissa.
We can exactly represent a float in radix b
from radix 2 if
b
is divisible by 2. This function calculates the exact number of
digits required to exactly represent that float.
According to the “Handbook of Floating Point Arithmetic”, for IEEE754, with emin being the min exponent, p2 being the precision, and b being the radix, the number of digits follows as:
−emin + p2 + ⌊(emin + 1) log(2, b) − log(1 − 2^(−p2), b)⌋
For f32, this follows as: emin = -126 p2 = 24
For f64, this follows as: emin = -1022 p2 = 53
In Python:
-emin + p2 + math.floor((emin+1)*math.log(2, b) - math.log(1-2**(-p2), b))
This was used to calculate the maximum number of digits for [2, 36].
source
Bitmask for the sign bit.
source
Bitmask for the exponent, including the hidden bit.
source
Bitmask for the hidden bit in exponent, which is an implicit 1 in the fraction.
source
Bitmask for the mantissa (fraction), excluding the hidden bit.
source
Size of the significand (mantissa) without hidden bit.
source
Bias of the exponet
source
Exponent portion of a denormal float.
source
Maximum exponent value in float.
source
Mask to determine if a full-carry occurred (1 in bit above hidden bit).
source
Minimum normal exponent value -(1 << (EXPONENT_SIZE - 1)) + 1
.
source
Smallest decimal exponent for a non-zero value.
source
Largest decimal exponent for a non-infinite value.
source
Minimum exponent that for a fast path case, or -⌊(MANTISSA_SIZE+1)/log2(10)⌋
source
Maximum exponent that for a fast path case, or ⌊(MANTISSA_SIZE+1)/log2(5)⌋
source
Maximum exponent that can be represented for a disguised-fast path case.
This is MAX_EXPONENT_FAST_PATH + ⌊(MANTISSA_SIZE+1)/log2(10)⌋
Provided Associated Constants§
Required Methods§
Provided Methods§
source
Get a small, integral power-of-radix for fast-path multiplication.
Safety
Safe as long as the exponent is smaller than the table size.
source
Returns true if the float is a denormal.
source
Get exponent component from the float.
source
Get mantissa (significand) component from float.