Trait RawFloat

Source
#[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) { ... }
}
🔬This is a nightly-only experimental API. (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§

Source

const INFINITY: Self

🔬This is a nightly-only experimental API. (dec2flt)
Source

const NEG_INFINITY: Self

🔬This is a nightly-only experimental API. (dec2flt)
Source

const NAN: Self

🔬This is a nightly-only experimental API. (dec2flt)
Source

const NEG_NAN: Self

🔬This is a nightly-only experimental API. (dec2flt)
Source

const BITS: u32

🔬This is a nightly-only experimental API. (dec2flt)

Bit width of the float

Source

const SIG_TOTAL_BITS: u32

🔬This is a nightly-only experimental API. (dec2flt)

The number of bits in the significand, including the hidden bit.

Source

const EXP_MASK: Self::Int

🔬This is a nightly-only experimental API. (dec2flt)
Source

const SIG_MASK: Self::Int

🔬This is a nightly-only experimental API. (dec2flt)
Source

const MIN_EXPONENT_ROUND_TO_EVEN: i32

🔬This is a nightly-only experimental API. (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.

Source

const MAX_EXPONENT_ROUND_TO_EVEN: i32

🔬This is a nightly-only experimental API. (dec2flt)
Source

const SMALLEST_POWER_OF_TEN: i32

🔬This is a nightly-only experimental API. (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§

Source

const SIG_BITS: u32 = _

🔬This is a nightly-only experimental API. (dec2flt)

The number of bits in the significand, excluding the hidden bit.

Source

const EXP_BITS: u32 = _

🔬This is a nightly-only experimental API. (dec2flt)

Number of bits in the exponent.

Source

const EXP_SAT: u32 = _

🔬This is a nightly-only experimental API. (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.

Source

const INFINITE_POWER: i32 = _

🔬This is a nightly-only experimental API. (dec2flt)

Signed version of EXP_SAT since we convert a lot.

Source

const EXP_BIAS: u32 = _

🔬This is a nightly-only experimental API. (dec2flt)

The exponent bias value. This is also the maximum value of the exponent.

Source

const EXP_MIN: i32 = _

🔬This is a nightly-only experimental API. (dec2flt)

Minimum exponent value of normal values.

Source

const LARGEST_POWER_OF_TEN: i32 = _

🔬This is a nightly-only experimental API. (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.

Source

const MAX_EXPONENT_FAST_PATH: i64 = _

🔬This is a nightly-only experimental API. (dec2flt)

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

Source

const MIN_EXPONENT_FAST_PATH: i64 = _

🔬This is a nightly-only experimental API. (dec2flt)

Minimum exponent for a fast path case, or -⌊(SIG_BITS+1)/log2(5)⌋

Source

const MAX_EXPONENT_DISGUISED_FAST_PATH: i64 = _

🔬This is a nightly-only experimental API. (dec2flt)

Maximum exponent that can be represented for a disguised-fast path case. This is MAX_EXPONENT_FAST_PATH + ⌊(SIG_BITS+1)/log2(10)⌋

Source

const MAX_MANTISSA_FAST_PATH: u64 = _

🔬This is a nightly-only experimental API. (dec2flt)

Maximum mantissa for the fast-path (1 << 53 for f64).

Required Associated Types§

Source

type Int: Integer + Into<u64>

🔬This is a nightly-only experimental API. (dec2flt)

The unsigned integer with the same size as the float

Required Methods§

Source

fn from_u64(v: u64) -> Self

🔬This is a nightly-only experimental API. (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.

Source

fn from_u64_bits(v: u64) -> Self

🔬This is a nightly-only experimental API. (dec2flt)

Performs a raw transmutation from an integer.

Source

fn pow10_fast_path(exponent: usize) -> Self

🔬This is a nightly-only experimental API. (dec2flt)

Gets a small power-of-ten for fast-path multiplication.

Source

fn classify(self) -> FpCategory

🔬This is a nightly-only experimental API. (dec2flt)

Returns the category that this number falls into.

Source

fn to_bits(self) -> Self::Int

🔬This is a nightly-only experimental API. (dec2flt)

Transmute to the integer representation

Provided Methods§

Source

fn integer_decode(self) -> (u64, i16, i8)

🔬This is a nightly-only experimental API. (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.

Implementors§

Source§

impl RawFloat for f32

Source§

const INFINITY: Self = +Inf_f32

Source§

const NEG_INFINITY: Self = -Inf_f32

Source§

const NAN: Self = NaN_f32

Source§

const NEG_NAN: Self = NaN_f32

Source§

const BITS: u32 = 32u32

Source§

const SIG_TOTAL_BITS: u32 = 24u32

Source§

const EXP_MASK: Self::Int = {transmute(0x7f800000): <f32 as num::dec2flt::float::RawFloat>::Int}

Source§

const SIG_MASK: Self::Int = {transmute(0x007fffff): <f32 as num::dec2flt::float::RawFloat>::Int}

Source§

const MIN_EXPONENT_ROUND_TO_EVEN: i32 = -17i32

Source§

const MAX_EXPONENT_ROUND_TO_EVEN: i32 = 10i32

Source§

const SMALLEST_POWER_OF_TEN: i32 = -65i32

Source§

type Int = u32

Source§

impl RawFloat for f64

Source§

const INFINITY: Self = +Inf_f64

Source§

const NEG_INFINITY: Self = -Inf_f64

Source§

const NAN: Self = NaN_f64

Source§

const NEG_NAN: Self = NaN_f64

Source§

const BITS: u32 = 64u32

Source§

const SIG_TOTAL_BITS: u32 = 53u32

Source§

const EXP_MASK: Self::Int = {transmute(0x7ff0000000000000): <f64 as num::dec2flt::float::RawFloat>::Int}

Source§

const SIG_MASK: Self::Int = {transmute(0x000fffffffffffff): <f64 as num::dec2flt::float::RawFloat>::Int}

Source§

const MIN_EXPONENT_ROUND_TO_EVEN: i32 = -4i32

Source§

const MAX_EXPONENT_ROUND_TO_EVEN: i32 = 23i32

Source§

const SMALLEST_POWER_OF_TEN: i32 = -342i32

Source§

type Int = u64