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: Self
pub const NEG_INFINITY: Self
Negative infinity.
Sourcepub const MIN_POSITIVE: Self
pub const MIN_POSITIVE: Self
Minimum positive normal value (2^-14 ≈ 6.104e-5).
Sourcepub const MIN_POSITIVE_SUBNORMAL: Self
pub const MIN_POSITIVE_SUBNORMAL: Self
Minimum positive subnormal value (2^-24 ≈ 5.96e-8).
Sourcepub const fn from_bits(bits: u16) -> Self
pub const fn from_bits(bits: u16) -> Self
Create a float16 from raw bits.
This is a const function that performs no validation.
Sourcepub fn from_f32(value: f32) -> Self
pub fn from_f32(value: f32) -> Self
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: Self) -> Option<Ordering>
pub fn partial_cmp_value(self, other: Self) -> Option<Ordering>
IEEE-754 partial comparison: returns None if either value is NaN.
Trait Implementations§
Source§impl ForyDefault for float16
impl ForyDefault for float16
Source§fn fory_default() -> Self
fn fory_default() -> Self
Source§impl PartialOrd for float16
impl PartialOrd for float16
Source§impl Serializer for float16
impl Serializer for float16
Source§fn fory_write_data(&self, context: &mut WriteContext<'_>) -> Result<(), Error>
fn fory_write_data(&self, context: &mut WriteContext<'_>) -> Result<(), Error>
Source§fn fory_read_data(context: &mut ReadContext<'_>) -> Result<Self, Error>
fn fory_read_data(context: &mut ReadContext<'_>) -> Result<Self, Error>
Source§fn fory_reserved_space() -> usize
fn fory_reserved_space() -> usize
Source§fn fory_get_type_id(_: &TypeResolver) -> Result<TypeId, Error>
fn fory_get_type_id(_: &TypeResolver) -> Result<TypeId, Error>
Source§fn fory_type_id_dyn(&self, _: &TypeResolver) -> Result<TypeId, Error>
fn fory_type_id_dyn(&self, _: &TypeResolver) -> Result<TypeId, Error>
Source§fn fory_static_type_id() -> TypeId
fn fory_static_type_id() -> TypeId
Source§fn as_any(&self) -> &dyn Any
fn as_any(&self) -> &dyn Any
&dyn Any for dynamic type checking. Read moreSource§fn fory_write_type_info(context: &mut WriteContext<'_>) -> Result<(), Error>
fn fory_write_type_info(context: &mut WriteContext<'_>) -> Result<(), Error>
Source§fn fory_read_type_info(context: &mut ReadContext<'_>) -> Result<(), Error>
fn fory_read_type_info(context: &mut ReadContext<'_>) -> Result<(), Error>
Source§fn fory_write(
&self,
context: &mut WriteContext<'_>,
ref_mode: RefMode,
write_type_info: bool,
has_generics: bool,
) -> Result<(), Error>where
Self: Sized,
fn fory_write(
&self,
context: &mut WriteContext<'_>,
ref_mode: RefMode,
write_type_info: bool,
has_generics: bool,
) -> Result<(), Error>where
Self: Sized,
Source§fn fory_write_data_generic(
&self,
context: &mut WriteContext<'_>,
has_generics: bool,
) -> Result<(), Error>
fn fory_write_data_generic( &self, context: &mut WriteContext<'_>, has_generics: bool, ) -> Result<(), Error>
Source§fn fory_read(
context: &mut ReadContext<'_>,
ref_mode: RefMode,
read_type_info: bool,
) -> Result<Self, Error>where
Self: Sized + ForyDefault,
fn fory_read(
context: &mut ReadContext<'_>,
ref_mode: RefMode,
read_type_info: bool,
) -> Result<Self, Error>where
Self: Sized + ForyDefault,
Source§fn fory_read_with_type_info(
context: &mut ReadContext<'_>,
ref_mode: RefMode,
type_info: Rc<TypeInfo>,
) -> Result<Self, Error>where
Self: Sized + ForyDefault,
fn fory_read_with_type_info(
context: &mut ReadContext<'_>,
ref_mode: RefMode,
type_info: Rc<TypeInfo>,
) -> Result<Self, Error>where
Self: Sized + ForyDefault,
Source§fn fory_is_none(&self) -> bool
fn fory_is_none(&self) -> bool
None value. Read moreSource§fn fory_is_polymorphic() -> boolwhere
Self: Sized,
fn fory_is_polymorphic() -> boolwhere
Self: Sized,
fn fory_is_wrapper_type() -> boolwhere
Self: Sized,
fn fory_get_type_info(
type_resolver: &TypeResolver,
) -> Result<Rc<TypeInfo>, Error>where
Self: Sized,
Source§fn fory_concrete_type_id(&self) -> TypeId
fn fory_concrete_type_id(&self) -> TypeId
std::any::TypeId for this instance. Read more