pub struct Float16(/* private fields */);Expand description
IEEE 754 binary16 (half-precision) floating-point type.
This is a 16-bit floating-point format with:
- 1 sign bit
- 5 exponent bits (bias = 15)
- 10 mantissa bits (with implicit leading 1 for normalized values)
Special values:
- ±0: exponent = 0, mantissa = 0
- ±Inf: exponent = 31, mantissa = 0
- NaN: exponent = 31, mantissa ≠ 0
- Subnormals: exponent = 0, mantissa ≠ 0
Implementations§
Source§impl float16
impl float16
Sourcepub const NEG_INFINITY: float16
pub const NEG_INFINITY: float16
Negative infinity.
Sourcepub const MIN_POSITIVE: float16
pub const MIN_POSITIVE: float16
Minimum positive normal value (2^-14 ≈ 6.104e-5).
Sourcepub const MIN_POSITIVE_SUBNORMAL: float16
pub const MIN_POSITIVE_SUBNORMAL: float16
Minimum positive subnormal value (2^-24 ≈ 5.96e-8).
Sourcepub const fn from_bits(bits: u16) -> float16
pub const fn from_bits(bits: u16) -> float16
Create a float16 from raw bits.
This is a const function that performs no validation.
Sourcepub fn from_f32(value: f32) -> float16
pub fn from_f32(value: f32) -> float16
Convert f32 to float16 using IEEE 754 round-to-nearest, ties-to-even.
Handles:
- NaN → NaN (preserves payload bits where possible, ensures quiet NaN)
- ±Inf → ±Inf
- ±0 → ±0 (preserves sign)
- Overflow → ±Inf
- Underflow → subnormal or ±0
- Normal values → rounded to nearest representable value
Sourcepub fn to_f32(self) -> f32
pub fn to_f32(self) -> f32
Convert float16 to f32 (exact conversion).
All float16 values are exactly representable in f32.
Sourcepub fn is_infinite(self) -> bool
pub fn is_infinite(self) -> bool
Returns true if this value is positive or negative infinity.
Sourcepub fn is_normal(self) -> bool
pub fn is_normal(self) -> bool
Returns true if this value is a normal number (not zero, subnormal, infinite, or NaN).
Sourcepub fn is_subnormal(self) -> bool
pub fn is_subnormal(self) -> bool
Returns true if this value is subnormal.
Sourcepub fn is_sign_negative(self) -> bool
pub fn is_sign_negative(self) -> bool
Returns true if the sign bit is set (negative).
Sourcepub fn is_sign_positive(self) -> bool
pub fn is_sign_positive(self) -> bool
Returns true if the sign bit is not set (positive).
Sourcepub fn partial_cmp_value(self, other: float16) -> Option<Ordering>
pub fn partial_cmp_value(self, other: float16) -> Option<Ordering>
IEEE-754 partial comparison: returns None if either value is NaN.