# 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    const MAX_DIGITS: usize;
        const SIGN_MASK: u64;
        const EXPONENT_MASK: u64;
        const HIDDEN_BIT_MASK: u64;
        const MANTISSA_MASK: u64;
        const MANTISSA_SIZE: i32;
        const EXPONENT_BIAS: i32;
        const DENORMAL_EXPONENT: i32;
        const MAX_EXPONENT: i32;
        const CARRY_MASK: u64;
        const MIN_EXPONENT_ROUND_TO_EVEN: i32;
        const MAX_EXPONENT_ROUND_TO_EVEN: i32;
        const MINIMUM_EXPONENT: i32;
        const SMALLEST_POWER_OF_TEN: i32;
        const LARGEST_POWER_OF_TEN: i32;
        const MIN_EXPONENT_FAST_PATH: i32;
        const MAX_EXPONENT_FAST_PATH: i32;
        const MAX_EXPONENT_DISGUISED_FAST_PATH: i32;
        const INVALID_FP: i32 = -32_768i32;
        const MAX_MANTISSA_FAST_PATH: u64 = _;
        const INFINITE_POWER: i32 = _;

        fn from_u64(u: u64) -> Self;
        fn from_bits(u: u64) -> Self;
        fn to_bits(self) -> u64;
        unsafe fn pow_fast_path(exponent: usize) -> Self;

        unsafe fn int_pow_fast_path(exponent: usize, radix: u32) -> u64 { ... }
        fn is_denormal(self) -> bool { ... }
        fn exponent(self) -> i32 { ... }
        fn mantissa(self) -> u64 { ... }
    }

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

#### const MAX_DIGITS: usize

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

#### const SIGN_MASK: u64

Bitmask for the sign bit.

source

#### const EXPONENT_MASK: u64

Bitmask for the exponent, including the hidden bit.

source

#### const HIDDEN_BIT_MASK: u64

Bitmask for the hidden bit in exponent, which is an implicit 1 in the fraction.

source

#### const MANTISSA_MASK: u64

Bitmask for the mantissa (fraction), excluding the hidden bit.

source

#### const MANTISSA_SIZE: i32

Size of the significand (mantissa) without hidden bit.

source

#### const EXPONENT_BIAS: i32

Bias of the exponet

source

#### const DENORMAL_EXPONENT: i32

Exponent portion of a denormal float.

source

#### const MAX_EXPONENT: i32

Maximum exponent value in float.

source

#### const CARRY_MASK: u64

Mask to determine if a full-carry occurred (1 in bit above hidden bit).

source

#### const MIN_EXPONENT_ROUND_TO_EVEN: i32

source

#### const MAX_EXPONENT_ROUND_TO_EVEN: i32

source

#### const MINIMUM_EXPONENT: i32

Minimum normal exponent value `-(1 << (EXPONENT_SIZE - 1)) + 1`.

source

#### const SMALLEST_POWER_OF_TEN: i32

Smallest decimal exponent for a non-zero value.

source

#### const LARGEST_POWER_OF_TEN: i32

Largest decimal exponent for a non-infinite value.

source

#### const MIN_EXPONENT_FAST_PATH: i32

Minimum exponent that for a fast path case, or `-⌊(MANTISSA_SIZE+1)/log2(10)⌋`

source

#### const MAX_EXPONENT_FAST_PATH: i32

Maximum exponent that for a fast path case, or `⌊(MANTISSA_SIZE+1)/log2(5)⌋`

source

#### const MAX_EXPONENT_DISGUISED_FAST_PATH: i32

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

source

#### const INVALID_FP: i32 = -32_768i32

Bias for marking an invalid extended float.

source

#### const MAX_MANTISSA_FAST_PATH: u64 = _

source

#### const INFINITE_POWER: i32 = _

## Required Methods

source

#### fn from_u64(u: u64) -> Self

Convert 64-bit integer to float.

source

#### fn from_bits(u: u64) -> Self

source

#### fn to_bits(self) -> u64

source

#### unsafe fn pow_fast_path(exponent: usize) -> Self

Get a small power-of-radix for fast-path multiplication.

##### Safety

Safe as long as the exponent is smaller than the table size.

## Provided Methods

source

#### unsafe fn int_pow_fast_path(exponent: usize, radix: u32) -> u64

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

#### fn is_denormal(self) -> bool

Returns true if the float is a denormal.

source

#### fn exponent(self) -> i32

Get exponent component from the float.

source

#### fn mantissa(self) -> u64

Get mantissa (significand) component from float.

## Implementations on Foreign Types

source

### impl Float for f32

source

#### const MAX_DIGITS: usize = 114usize

source

#### const SIGN_MASK: u64 = 2_147_483_648u64

source

#### const EXPONENT_MASK: u64 = 2_139_095_040u64

source

#### const HIDDEN_BIT_MASK: u64 = 8_388_608u64

source

#### const MANTISSA_MASK: u64 = 8_388_607u64

source

#### const MANTISSA_SIZE: i32 = 23i32

source

#### const EXPONENT_BIAS: i32 = 150i32

source

#### const DENORMAL_EXPONENT: i32 = -149i32

source

#### const MAX_EXPONENT: i32 = 105i32

source

#### const CARRY_MASK: u64 = 16_777_216u64

source

#### const MIN_EXPONENT_ROUND_TO_EVEN: i32 = -17i32

source

#### const MAX_EXPONENT_ROUND_TO_EVEN: i32 = 10i32

source

#### const MINIMUM_EXPONENT: i32 = -127i32

source

#### const SMALLEST_POWER_OF_TEN: i32 = -65i32

source

#### const LARGEST_POWER_OF_TEN: i32 = 38i32

source

#### const MIN_EXPONENT_FAST_PATH: i32 = -10i32

source

#### const MAX_EXPONENT_FAST_PATH: i32 = 10i32

source

#### const MAX_EXPONENT_DISGUISED_FAST_PATH: i32 = 17i32

source

#### unsafe fn pow_fast_path(exponent: usize) -> Self

source

#### fn from_u64(u: u64) -> f32

source

#### fn from_bits(u: u64) -> f32

source

#### fn to_bits(self) -> u64

source

### impl Float for f64

source

#### const MAX_DIGITS: usize = 769usize

source

#### const SIGN_MASK: u64 = 9_223_372_036_854_775_808u64

source

#### const EXPONENT_MASK: u64 = 9_218_868_437_227_405_312u64

source

#### const HIDDEN_BIT_MASK: u64 = 4_503_599_627_370_496u64

source

#### const MANTISSA_MASK: u64 = 4_503_599_627_370_495u64

source

#### const MANTISSA_SIZE: i32 = 52i32

source

#### const EXPONENT_BIAS: i32 = 1_075i32

source

#### const DENORMAL_EXPONENT: i32 = -1_074i32

source

#### const MAX_EXPONENT: i32 = 972i32

source

#### const CARRY_MASK: u64 = 9_007_199_254_740_992u64

source

#### const MIN_EXPONENT_ROUND_TO_EVEN: i32 = -4i32

source

#### const MAX_EXPONENT_ROUND_TO_EVEN: i32 = 23i32

source

#### const MINIMUM_EXPONENT: i32 = -1_023i32

source

#### const SMALLEST_POWER_OF_TEN: i32 = -342i32

source

#### const LARGEST_POWER_OF_TEN: i32 = 308i32

source

#### const MIN_EXPONENT_FAST_PATH: i32 = -22i32

source

#### const MAX_EXPONENT_FAST_PATH: i32 = 22i32

source

#### const MAX_EXPONENT_DISGUISED_FAST_PATH: i32 = 37i32

source

#### unsafe fn pow_fast_path(exponent: usize) -> Self

source

#### fn from_u64(u: u64) -> f64

source

#### fn from_bits(u: u64) -> f64

source

#### fn to_bits(self) -> u64

## Implementors