Trait minimal_lexical::Float [−][src]
pub trait Float: Number + Neg<Output = Self> { type Unsigned: Integer;}Show associated constants and methods
const ZERO: Self; const MAX_DIGITS: usize; const SIGN_MASK: Self::Unsigned; const EXPONENT_MASK: Self::Unsigned; const HIDDEN_BIT_MASK: Self::Unsigned; const MANTISSA_MASK: Self::Unsigned; const INFINITY_BITS: Self::Unsigned; const NEGATIVE_INFINITY_BITS: Self::Unsigned; const MANTISSA_SIZE: i32; const EXPONENT_BIAS: i32; const DENORMAL_EXPONENT: i32; const MAX_EXPONENT: i32; const DEFAULT_SHIFT: i32; const CARRY_MASK: u64; fn exponent_limit() -> (i32, i32); fn mantissa_limit() -> i32; fn pow10(self, n: i32) -> Self; fn from_bits(u: Self::Unsigned) -> Self; fn to_bits(self) -> Self::Unsigned; fn is_sign_positive(self) -> bool; fn is_sign_negative(self) -> bool; fn is_denormal(self) -> bool { ... } fn is_special(self) -> bool { ... } fn is_nan(self) -> bool { ... } fn is_inf(self) -> bool { ... } fn exponent(self) -> i32 { ... } fn mantissa(self) -> Self::Unsigned { ... } fn next_positive(self) -> Self { ... } fn round_positive_even(self) -> Self { ... }
Get exact exponent limit for radix.
Associated Types
Loading content...Associated Constants
const ZERO: Self
[src]
Literal zero.
const MAX_DIGITS: usize
[src]
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].
const SIGN_MASK: Self::Unsigned
[src]
Bitmask for the sign bit.
const EXPONENT_MASK: Self::Unsigned
[src]
Bitmask for the exponent, including the hidden bit.
const HIDDEN_BIT_MASK: Self::Unsigned
[src]
Bitmask for the hidden bit in exponent, which is an implicit 1 in the fraction.
const MANTISSA_MASK: Self::Unsigned
[src]
Bitmask for the mantissa (fraction), excluding the hidden bit.
const INFINITY_BITS: Self::Unsigned
[src]
Positive infinity as bits.
const NEGATIVE_INFINITY_BITS: Self::Unsigned
[src]
Positive infinity as bits.
const MANTISSA_SIZE: i32
[src]
Size of the significand (mantissa) without hidden bit.
const EXPONENT_BIAS: i32
[src]
Bias of the exponet
const DENORMAL_EXPONENT: i32
[src]
Exponent portion of a denormal float.
const MAX_EXPONENT: i32
[src]
Maximum exponent value in float.
const DEFAULT_SHIFT: i32
[src]
Default number of bits to shift (or 64 - mantissa size - 1).
const CARRY_MASK: u64
[src]
Mask to determine if a full-carry occurred (1 in bit above hidden bit).
Required methods
fn exponent_limit() -> (i32, i32)
[src]
Get min and max exponent limits (exact) from radix.
fn mantissa_limit() -> i32
[src]
Get the number of digits that can be shifted from exponent to mantissa.
fn pow10(self, n: i32) -> Self
[src]
fn from_bits(u: Self::Unsigned) -> Self
[src]
fn to_bits(self) -> Self::Unsigned
[src]
fn is_sign_positive(self) -> bool
[src]
fn is_sign_negative(self) -> bool
[src]
Provided methods
fn is_denormal(self) -> bool
[src]
Returns true if the float is a denormal.
fn is_special(self) -> bool
[src]
Returns true if the float is a NaN or Infinite.
fn is_nan(self) -> bool
[src]
Returns true if the float is NaN.
fn is_inf(self) -> bool
[src]
Returns true if the float is infinite.
fn exponent(self) -> i32
[src]
Get exponent component from the float.
fn mantissa(self) -> Self::Unsigned
[src]
Get mantissa (significand) component from float.
fn next_positive(self) -> Self
[src]
Get next greater float for a positive float. Value must be >= 0.0 and < INFINITY.
fn round_positive_even(self) -> Self
[src]
Round a positive number to even.
Implementations on Foreign Types
impl Float for f32
[src]
impl Float for f32
[src]type Unsigned = u32
const ZERO: f32
[src]
const MAX_DIGITS: usize
[src]
const SIGN_MASK: u32
[src]
const EXPONENT_MASK: u32
[src]
const HIDDEN_BIT_MASK: u32
[src]
const MANTISSA_MASK: u32
[src]
const INFINITY_BITS: u32
[src]
const NEGATIVE_INFINITY_BITS: u32
[src]
const MANTISSA_SIZE: i32
[src]
const EXPONENT_BIAS: i32
[src]
const DENORMAL_EXPONENT: i32
[src]
const MAX_EXPONENT: i32
[src]
const DEFAULT_SHIFT: i32
[src]
const CARRY_MASK: u64
[src]
fn exponent_limit() -> (i32, i32)
[src]
fn mantissa_limit() -> i32
[src]
fn pow10(self, n: i32) -> f32
[src]
fn from_bits(u: u32) -> f32
[src]
fn to_bits(self) -> u32
[src]
fn is_sign_positive(self) -> bool
[src]
fn is_sign_negative(self) -> bool
[src]
impl Float for f64
[src]
impl Float for f64
[src]