pub trait Float:
Copy
+ Debug
+ PartialEq
+ PartialOrd
+ AddAssign
+ MulAssign
+ Add<Output = Self>
+ Sub<Output = Self>
+ Mul<Output = Self>
+ Div<Output = Self>
+ Rem<Output = Self>
+ Neg<Output = Self>
+ 'static {
type Int: Int<OtherSign = Self::SignedInt, Unsigned = Self::Int>;
type SignedInt: Int + MinInt<OtherSign = Self::Int, Unsigned = Self::Int> + Neg<Output = Self::SignedInt>;
Show 27 associated constants and 19 methods
const ZERO: Self;
const NEG_ZERO: Self;
const ONE: Self;
const NEG_ONE: Self;
const INFINITY: Self;
const NEG_INFINITY: Self;
const NAN: Self;
const NEG_NAN: Self;
const MAX: Self;
const MIN: Self;
const EPSILON: Self;
const PI: Self;
const NEG_PI: Self;
const FRAC_PI_2: Self;
const MIN_POSITIVE_NORMAL: Self;
const BITS: u32;
const SIG_BITS: u32;
const SIGN_MASK: Self::Int;
const SIG_MASK: Self::Int;
const EXP_MASK: Self::Int;
const IMPLICIT_BIT: Self::Int;
const EXP_BITS: u32 = _;
const EXP_SAT: u32 = _;
const EXP_BIAS: u32 = _;
const EXP_MAX: i32 = _;
const EXP_MIN: i32 = _;
const EXP_MIN_SUBNORM: i32 = _;
// Required methods
fn to_bits(self) -> Self::Int;
fn is_nan(self) -> bool;
fn is_infinite(self) -> bool;
fn is_sign_negative(self) -> bool;
fn from_bits(a: Self::Int) -> Self;
fn abs(self) -> Self;
fn copysign(self, other: Self) -> Self;
fn fma(self, y: Self, z: Self) -> Self;
fn normalize(significand: Self::Int) -> (i32, Self::Int);
// Provided methods
fn to_bits_signed(self) -> Self::SignedInt { ... }
fn biteq(self, rhs: Self) -> bool { ... }
fn eq_repr(self, rhs: Self) -> bool { ... }
fn is_sign_positive(self) -> bool { ... }
fn is_subnormal(self) -> bool { ... }
fn ex(self) -> u32 { ... }
fn exp_unbiased(self) -> i32 { ... }
fn frac(self) -> Self::Int { ... }
fn from_parts(negative: bool, exponent: u32, significand: Self::Int) -> Self { ... }
fn signum(self) -> Self { ... }
}
Expand description
Trait for some basic operations on floats
Required Associated Constants§
const ZERO: Self
const NEG_ZERO: Self
const ONE: Self
const NEG_ONE: Self
const INFINITY: Self
const NEG_INFINITY: Self
const NAN: Self
const NEG_NAN: Self
const MAX: Self
const MIN: Self
const EPSILON: Self
const PI: Self
const NEG_PI: Self
const FRAC_PI_2: Self
const MIN_POSITIVE_NORMAL: Self
Sourceconst IMPLICIT_BIT: Self::Int
const IMPLICIT_BIT: Self::Int
The implicit bit of the float format
Provided Associated Constants§
Sourceconst EXP_SAT: u32 = _
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.
Sourceconst EXP_MIN_SUBNORM: i32 = _
const EXP_MIN_SUBNORM: i32 = _
Minimum subnormal exponent value.
Required Associated Types§
Required Methods§
Sourcefn is_infinite(self) -> bool
fn is_infinite(self) -> bool
Returns true if the value is +inf or -inf.
Sourcefn is_sign_negative(self) -> bool
fn is_sign_negative(self) -> bool
Returns true if the sign is negative. Extracts the sign bit regardless of zero or NaN.
fn abs(self) -> Self
Provided Methods§
Sourcefn to_bits_signed(self) -> Self::SignedInt
fn to_bits_signed(self) -> Self::SignedInt
Returns self
transmuted to Self::SignedInt
Sourcefn eq_repr(self, rhs: Self) -> bool
fn eq_repr(self, rhs: Self) -> bool
Checks if two floats have the same bit representation. Except for NaNs! NaN can be represented in multiple different ways.
This method returns true
if two NaNs are compared. Use biteq
instead
if NaN
should not be treated separately.
Sourcefn is_sign_positive(self) -> bool
fn is_sign_positive(self) -> bool
Returns true if the sign is positive. Extracts the sign bit regardless of zero or NaN.
Sourcefn is_subnormal(self) -> bool
fn is_subnormal(self) -> bool
Returns if self
is subnormal.
Sourcefn ex(self) -> u32
fn ex(self) -> u32
Returns the exponent, not adjusting for bias, not accounting for subnormals or zero.
Sourcefn exp_unbiased(self) -> i32
fn exp_unbiased(self) -> i32
Extract the exponent and adjust it for bias, not accounting for subnormals or zero.
Sourcefn frac(self) -> Self::Int
fn frac(self) -> Self::Int
Returns the significand with no implicit bit (or the “fractional” part)
Sourcefn from_parts(negative: bool, exponent: u32, significand: Self::Int) -> Self
fn from_parts(negative: bool, exponent: u32, significand: Self::Int) -> Self
Constructs a Self
from its parts. Inputs are treated as bits and shifted into position.
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.