#[repr(transparent)]pub struct F16 {
pub bits: u16,
}Expand description
A newtype containing the raw bits of an IEEE 754 binary16 floating point number.
Values of this type are hashable and have a well-defined total order: the one given
by Self::total_cmp. As a consequence, +0.0 is not equal to -0.0, and NaN
compares equal to NaN if both NaN values have exactly the same bit pattern.
§Features
Crate feature f16 enables use of the Rust f16 primitive type, which is a
nightly-only language feature that’s only functional on certain architectures.
Fields§
§bits: u16The raw bits representing this float value.
Implementations§
Source§impl F16
impl F16
Sourcepub const MANTISSA_BITS: usize
pub const MANTISSA_BITS: usize
Number of bits in the mantissa representation.
Sourcepub const MANTISSA_DIGITS: usize
pub const MANTISSA_DIGITS: usize
Number of significant digits in base 2.
Note that the size of the mantissa in the bitwise representation is one smaller than this, since the leading 1 is not stored explicitly.
Sourcepub const SNAN: Self
pub const SNAN: Self
Not a Number (NaN) with sign bit 0, is_quiet bit 0, and arbitrary payload.
Sourcepub const QNAN: Self
pub const QNAN: Self
Not a Number (NaN) with sign bit 0, is_quiet bit 1, and arbitrary payload.
Sourcepub const NEG_INFINITY: Self
pub const NEG_INFINITY: Self
Negative infinity (−∞).
Sourcepub const NEG_SNAN: Self
pub const NEG_SNAN: Self
Not a Number (NaN) with sign bit 1, is_quiet bit 0, and arbitrary payload.
Sourcepub const NEG_QNAN: Self
pub const NEG_QNAN: Self
Not a Number (NaN) with sign bit 1, is_quiet bit 1, and arbitrary payload.
Sourcepub const MIN_POSITIVE: Self
pub const MIN_POSITIVE: Self
The positive normal value with the least possible absolute magnitude.
Sourcepub const MAX_NEGATIVE: Self
pub const MAX_NEGATIVE: Self
The negative normal value with the least possible absolute magnitude.
Sourcepub const fn is_sign_positive(&self) -> bool
pub const fn is_sign_positive(&self) -> bool
Returns true if self has a positive sign, including +0.0, +∞, and NaN with positive sign bit.
Sourcepub const fn is_sign_negative(&self) -> bool
pub const fn is_sign_negative(&self) -> bool
Returns true if self has a negative sign, including -0.0, -∞, and NaN with negative sign bit.
Sourcepub const fn classify(&self) -> FpCategory
pub const fn classify(&self) -> FpCategory
Returns the floating point category of the number.
Sourcepub const fn is_subnormal(&self) -> bool
pub const fn is_subnormal(&self) -> bool
Returns true if the number is subnormal.
Sourcepub const fn is_infinite(&self) -> bool
pub const fn is_infinite(&self) -> bool
Returns true if the number is subnormal.
Sourcepub const fn abs(&self) -> Self
pub const fn abs(&self) -> Self
Computes the absolute value of self.
The result is always exact. The result will always test true with Self::is_sign_positive.
Sourcepub const fn signum(&self) -> Self
pub const fn signum(&self) -> Self
Returns a number that represents the sign of self.
Self::ONEif the number is positive, including+0.0or+∞Self::NEG_ONEif the number is negative, including-0.0or-∞selfif the number is NaN
Sourcepub const fn copysign(&self, sign: Self) -> Self
pub const fn copysign(&self, sign: Self) -> Self
Returns a number composed of the magnitude of self and the sign of sign.
Sourcepub const fn total_cmp(&self, rhs: Self) -> Ordering
pub const fn total_cmp(&self, rhs: Self) -> Ordering
Returns the ordering between self and rhs.
Unlike the standard partial comparison between floating point numbers, this
comparison always produces an ordering in accordance to the totalOrder predicate
as defined in the IEEE 754 (2008 revision) floating point standard. The values are
ordered in the following sequence:
- negative quiet NaN
- negative signaling NaN
- negative infinity
- negative numbers
- negative subnormal numbers
- negative zero
- positive zero
- positive subnormal numbers
- positive numbers
- positive infinity
- positive signaling NaN
- positive quiet NaN
Sourcepub const fn clamp(&self, min: Self, max: Self) -> Self
pub const fn clamp(&self, min: Self, max: Self) -> Self
Restrict a value to a certain interval unless it is NaN.
Returns max if self is greater than max, and min if self is less than
min. Otherwise this returns self.
Note that this function returns NaN if the initial value was NaN as well.
§Panics
Panics if min > max, min is NaN, or max is NaN.