Trait Float

pub trait Float: Sized + Div<Output = Self> + Neg<Output = Self> + Mul<Output = Self> + Add<Output = Self> + Debug + PartialEq + PartialOrd + Default + Clone + Copy

A helper trait to avoid duplicating basically all the conversion code for IEEE floats.

Associated Types

type Int: Int + Into<u64>;

The unsigned integer with the same size as the float

Associated Constants

const INFINITY: Self;
const NEG_INFINITY: Self;
const NAN: Self;
const NEG_NAN: Self;
const BITS: u32;

Bit width of the float

const SIG_TOTAL_BITS: u32;

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

const EXP_MASK: Self::Int;
const SIG_MASK: Self::Int;
const SIG_BITS: u32 = _;

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

const EXP_BITS: u32 = _;

Number of bits in the exponent.

const EXP_SAT: u32 = _;

The saturated (maximum bitpattern) value of the exponent, i.e. the infinite representation.

This shifted fully right, use EXP_MASK for the shifted value.

const INFINITE_POWER: i32 = _;

Signed version of EXP_SAT since we convert a lot.

const EXP_BIAS: u32 = _;

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

const EXP_MIN: i32 = _;

Minimum exponent value of normal values.

const MIN_EXPONENT_ROUND_TO_EVEN: i32;

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;
const LARGEST_POWER_OF_TEN: i32 = _;

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.

const SMALLEST_POWER_OF_TEN: i32;

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.

Required Methods

fn classify(self) -> FpCategory

Returns the category that this number falls into.

fn to_bits(self) -> Self::Int

Transmute to the integer representation

Implementors