Skip to main content

Float

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

Available on crate feature floats only.
Source§

const ZERO: f32 = 0.0

Source§

const ONE: f32 = 1.0

Source§

const TWO: f32 = 2.0

Source§

const MAX: f32 = f32::MAX

Source§

const MIN: f32 = f32::MIN

Source§

const INFINITY: f32 = f32::INFINITY

Source§

const NEG_INFINITY: f32 = f32::NEG_INFINITY

Source§

const NAN: f32 = f32::NAN

Source§

const BITS: usize

Source§

const SIGN_MASK: Self::Unsigned = 0x80000000

Source§

const EXPONENT_MASK: Self::Unsigned = 0x7F800000

Source§

const HIDDEN_BIT_MASK: Self::Unsigned = 0x00800000

Source§

const MANTISSA_MASK: Self::Unsigned = 0x007FFFFF

Source§

const CARRY_MASK: Self::Unsigned

Source§

const INFINITY_BITS: Self::Unsigned = 0x7F800000

Source§

const NEGATIVE_INFINITY_BITS: Self::Unsigned

Source§

const EXPONENT_SIZE: i32 = 8

Source§

const MANTISSA_SIZE: i32 = 23

Source§

const EXPONENT_BIAS: i32

Source§

const DENORMAL_EXPONENT: i32

Source§

const MAX_EXPONENT: i32

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

Available on crate feature floats only.
Source§

const ZERO: f64 = 0.0

Source§

const ONE: f64 = 1.0

Source§

const TWO: f64 = 2.0

Source§

const MAX: f64 = f64::MAX

Source§

const MIN: f64 = f64::MIN

Source§

const INFINITY: f64 = f64::INFINITY

Source§

const NEG_INFINITY: f64 = f64::NEG_INFINITY

Source§

const NAN: f64 = f64::NAN

Source§

const BITS: usize

Source§

const SIGN_MASK: Self::Unsigned = 0x8000000000000000

Source§

const EXPONENT_MASK: Self::Unsigned = 0x7FF0000000000000

Source§

const HIDDEN_BIT_MASK: Self::Unsigned = 0x0010000000000000

Source§

const MANTISSA_MASK: Self::Unsigned = 0x000FFFFFFFFFFFFF

Source§

const CARRY_MASK: Self::Unsigned

Source§

const INFINITY_BITS: Self::Unsigned = 0x7FF0000000000000

Source§

const NEGATIVE_INFINITY_BITS: Self::Unsigned

Source§

const EXPONENT_SIZE: i32 = 11

Source§

const MANTISSA_SIZE: i32 = 52

Source§

const EXPONENT_BIAS: i32

Source§

const DENORMAL_EXPONENT: i32

Source§

const MAX_EXPONENT: i32

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§