Trait lexical_util::num::Float

source ·
pub trait Float: Number + Neg<Output = Self> {
    type Unsigned: UnsignedInteger;
Show 21 associated constants and 22 methods const ZERO: Self; const ONE: Self; const TWO: Self; const MAX: Self; const MIN: Self; const INFINITY: Self; const NEG_INFINITY: Self; const NAN: Self; const BITS: usize; const SIGN_MASK: Self::Unsigned; const EXPONENT_MASK: Self::Unsigned; const HIDDEN_BIT_MASK: Self::Unsigned; const MANTISSA_MASK: Self::Unsigned; const CARRY_MASK: Self::Unsigned; const INFINITY_BITS: Self::Unsigned; const NEGATIVE_INFINITY_BITS: Self::Unsigned; const EXPONENT_SIZE: i32; const MANTISSA_SIZE: i32; const EXPONENT_BIAS: i32; const DENORMAL_EXPONENT: i32; const MAX_EXPONENT: i32; // Required methods fn to_bits(self) -> Self::Unsigned; fn from_bits(u: Self::Unsigned) -> Self; fn ln(self) -> Self; fn floor(self) -> Self; fn is_sign_positive(self) -> bool; fn is_sign_negative(self) -> bool; // Provided methods fn is_denormal(self) -> bool { ... } fn is_special(self) -> bool { ... } fn is_nan(self) -> bool { ... } fn is_inf(self) -> bool { ... } fn is_odd(self) -> bool { ... } fn is_even(self) -> bool { ... } fn needs_negative_sign(self) -> bool { ... } fn exponent(self) -> i32 { ... } fn mantissa(self) -> Self::Unsigned { ... } fn next(self) -> Self { ... } fn next_positive(self) -> Self { ... } fn prev(self) -> Self { ... } fn prev_positive(self) -> Self { ... } fn round_positive_even(self) -> Self { ... } fn max_finite(self, f: Self) -> Self { ... } fn min_finite(self, f: Self) -> Self { ... }
}
Expand description

Float information for native float types.

Required Associated Types§

source

type Unsigned: UnsignedInteger

Unsigned type of the same size.

Required Associated Constants§

source

const ZERO: Self

source

const ONE: Self

source

const TWO: Self

source

const MAX: Self

source

const MIN: Self

source

const INFINITY: Self

source

const NEG_INFINITY: Self

source

const NAN: Self

source

const BITS: usize

source

const SIGN_MASK: Self::Unsigned

Bitmask for the sign bit.

source

const EXPONENT_MASK: Self::Unsigned

Bitmask for the exponent, including the hidden bit.

source

const HIDDEN_BIT_MASK: Self::Unsigned

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

source

const MANTISSA_MASK: Self::Unsigned

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

source

const CARRY_MASK: Self::Unsigned

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

source

const INFINITY_BITS: Self::Unsigned

Positive infinity as bits.

source

const NEGATIVE_INFINITY_BITS: Self::Unsigned

Positive infinity as bits.

source

const EXPONENT_SIZE: i32

Size of the exponent.

source

const MANTISSA_SIZE: i32

Size of the significand (mantissa) without hidden bit.

source

const EXPONENT_BIAS: i32

Bias of the exponent.

source

const DENORMAL_EXPONENT: i32

Exponent portion of a denormal float.

source

const MAX_EXPONENT: i32

Maximum exponent value in float.

Required Methods§

source

fn to_bits(self) -> Self::Unsigned

source

fn from_bits(u: Self::Unsigned) -> Self

source

fn ln(self) -> Self

source

fn floor(self) -> Self

source

fn is_sign_positive(self) -> bool

source

fn is_sign_negative(self) -> bool

Provided Methods§

source

fn is_denormal(self) -> bool

Returns true if the float is a denormal.

source

fn is_special(self) -> bool

Returns true if the float is a NaN or Infinite.

source

fn is_nan(self) -> bool

Returns true if the float is NaN.

source

fn is_inf(self) -> bool

Returns true if the float is infinite.

source

fn is_odd(self) -> bool

Returns true if the float’s least-significant mantissa bit is odd.

source

fn is_even(self) -> bool

Returns true if the float’s least-significant mantissa bit is even.

source

fn needs_negative_sign(self) -> bool

Returns true if the float needs a negative sign when serializing it.

This is true if it’s -0.0 or it’s below 0 and not NaN. But inf values need the sign.

source

fn exponent(self) -> i32

Get exponent component from the float.

source

fn mantissa(self) -> Self::Unsigned

Get mantissa (significand) component from float.

source

fn next(self) -> Self

Get next greater float.

source

fn next_positive(self) -> Self

Get next greater float for a positive float. Value must be >= 0.0 and < INFINITY.

source

fn prev(self) -> Self

Get previous greater float, such that self.prev().next() == self.

source

fn prev_positive(self) -> Self

Get previous greater float for a positive float. Value must be > 0.0.

source

fn round_positive_even(self) -> Self

Round a positive number to even.

source

fn max_finite(self, f: Self) -> Self

Get the max of two finite numbers.

source

fn min_finite(self, f: Self) -> Self

Get the min of two finite numbers.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Float for f32

§

type Unsigned = u32

source§

const ZERO: f32 = 0f32

source§

const ONE: f32 = 1f32

source§

const TWO: f32 = 2f32

source§

const MAX: f32 = 3.40282347E+38f32

source§

const MIN: f32 = -3.40282347E+38f32

source§

const INFINITY: f32 = +Inf_f32

source§

const NEG_INFINITY: f32 = -Inf_f32

source§

const NAN: f32 = NaN_f32

source§

const BITS: usize = 32usize

source§

const SIGN_MASK: Self::Unsigned = {transmute(0x80000000): <f32 as num::Float>::Unsigned}

source§

const EXPONENT_MASK: Self::Unsigned = {transmute(0x7f800000): <f32 as num::Float>::Unsigned}

source§

const HIDDEN_BIT_MASK: Self::Unsigned = {transmute(0x00800000): <f32 as num::Float>::Unsigned}

source§

const MANTISSA_MASK: Self::Unsigned = {transmute(0x007fffff): <f32 as num::Float>::Unsigned}

source§

const CARRY_MASK: Self::Unsigned = {transmute(0x01000000): <f32 as num::Float>::Unsigned}

source§

const INFINITY_BITS: Self::Unsigned = {transmute(0x7f800000): <f32 as num::Float>::Unsigned}

source§

const NEGATIVE_INFINITY_BITS: Self::Unsigned = {transmute(0xff800000): <f32 as num::Float>::Unsigned}

source§

const EXPONENT_SIZE: i32 = 8i32

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§

fn to_bits(self) -> u32

source§

fn from_bits(u: u32) -> f32

source§

fn ln(self) -> f32

source§

fn floor(self) -> f32

source§

fn is_sign_positive(self) -> bool

source§

fn is_sign_negative(self) -> bool

source§

impl Float for f64

§

type Unsigned = u64

source§

const ZERO: f64 = 0f64

source§

const ONE: f64 = 1f64

source§

const TWO: f64 = 2f64

source§

const MAX: f64 = 1.7976931348623157E+308f64

source§

const MIN: f64 = -1.7976931348623157E+308f64

source§

const INFINITY: f64 = +Inf_f64

source§

const NEG_INFINITY: f64 = -Inf_f64

source§

const NAN: f64 = NaN_f64

source§

const BITS: usize = 64usize

source§

const SIGN_MASK: Self::Unsigned = {transmute(0x8000000000000000): <f64 as num::Float>::Unsigned}

source§

const EXPONENT_MASK: Self::Unsigned = {transmute(0x7ff0000000000000): <f64 as num::Float>::Unsigned}

source§

const HIDDEN_BIT_MASK: Self::Unsigned = {transmute(0x0010000000000000): <f64 as num::Float>::Unsigned}

source§

const MANTISSA_MASK: Self::Unsigned = {transmute(0x000fffffffffffff): <f64 as num::Float>::Unsigned}

source§

const CARRY_MASK: Self::Unsigned = {transmute(0x0020000000000000): <f64 as num::Float>::Unsigned}

source§

const INFINITY_BITS: Self::Unsigned = {transmute(0x7ff0000000000000): <f64 as num::Float>::Unsigned}

source§

const NEGATIVE_INFINITY_BITS: Self::Unsigned = {transmute(0xfff0000000000000): <f64 as num::Float>::Unsigned}

source§

const EXPONENT_SIZE: i32 = 11i32

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§

fn to_bits(self) -> u64

source§

fn from_bits(u: u64) -> f64

source§

fn ln(self) -> f64

source§

fn floor(self) -> f64

source§

fn is_sign_positive(self) -> bool

source§

fn is_sign_negative(self) -> bool

Implementors§