lexical_util::num

Trait 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 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 Associated Types§

Source

type Unsigned: UnsignedInteger

Unsigned type of the same size.

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.

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.

Implementations on Foreign Types§

Source§

impl Float for f32

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§

type Unsigned = u32

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

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§

type Unsigned = u64

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§