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§
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
Sourceconst EXPONENT_MASK: Self::Unsigned
const EXPONENT_MASK: Self::Unsigned
Bitmask for the exponent, including the hidden bit.
Sourceconst HIDDEN_BIT_MASK: Self::Unsigned
const HIDDEN_BIT_MASK: Self::Unsigned
Bitmask for the hidden bit in exponent, which is an implicit 1 in the fraction.
Sourceconst MANTISSA_MASK: Self::Unsigned
const MANTISSA_MASK: Self::Unsigned
Bitmask for the mantissa (fraction), excluding the hidden bit.
Sourceconst CARRY_MASK: Self::Unsigned
const CARRY_MASK: Self::Unsigned
Mask to determine if a full-carry occurred (1 in bit above hidden bit).
Sourceconst INFINITY_BITS: Self::Unsigned
const INFINITY_BITS: Self::Unsigned
Positive infinity as bits.
Sourceconst NEGATIVE_INFINITY_BITS: Self::Unsigned
const NEGATIVE_INFINITY_BITS: Self::Unsigned
Positive infinity as bits.
Sourceconst EXPONENT_SIZE: i32
const EXPONENT_SIZE: i32
Size of the exponent.
Sourceconst MANTISSA_SIZE: i32
const MANTISSA_SIZE: i32
Size of the significand (mantissa) without hidden bit.
Sourceconst EXPONENT_BIAS: i32
const EXPONENT_BIAS: i32
Bias of the exponent.
Sourceconst DENORMAL_EXPONENT: i32
const DENORMAL_EXPONENT: i32
Exponent portion of a denormal float.
Sourceconst MAX_EXPONENT: i32
const MAX_EXPONENT: i32
Maximum exponent value in float.
Required Associated Types§
Sourcetype Unsigned: UnsignedInteger
type Unsigned: UnsignedInteger
Unsigned type of the same size.
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§
Sourcefn is_denormal(self) -> bool
fn is_denormal(self) -> bool
Returns true if the float is a denormal.
Sourcefn is_special(self) -> bool
fn is_special(self) -> bool
Returns true if the float is a NaN or Infinite.
Sourcefn needs_negative_sign(self) -> bool
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.
Sourcefn next_positive(self) -> Self
fn next_positive(self) -> Self
Get next greater float for a positive float. Value must be >= 0.0 and < INFINITY.
Sourcefn prev_positive(self) -> Self
fn prev_positive(self) -> Self
Get previous greater float for a positive float. Value must be > 0.0.
Sourcefn round_positive_even(self) -> Self
fn round_positive_even(self) -> Self
Round a positive number to even.
Sourcefn max_finite(self, f: Self) -> Self
fn max_finite(self, f: Self) -> Self
Get the max of two finite numbers.
Sourcefn min_finite(self, f: Self) -> Self
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.