Skip to main content

float16

Struct float16 

Source
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

Source

pub const ZERO: Self

Positive zero (+0.0).

Source

pub const NEG_ZERO: Self

Negative zero (-0.0).

Source

pub const INFINITY: Self

Positive infinity.

Source

pub const NEG_INFINITY: Self

Negative infinity.

Source

pub const NAN: Self

Quiet NaN (canonical).

Source

pub const MAX: Self

Maximum finite value (65504.0).

Source

pub const MIN_POSITIVE: Self

Minimum positive normal value (2^-14 ≈ 6.104e-5).

Source

pub const MIN_POSITIVE_SUBNORMAL: Self

Minimum positive subnormal value (2^-24 ≈ 5.96e-8).

Source

pub const fn from_bits(bits: u16) -> Self

Create a float16 from raw bits.

This is a const function that performs no validation.

Source

pub const fn to_bits(self) -> u16

Extract the raw bit representation.

Source

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
Source

pub fn to_f32(self) -> f32

Convert float16 to f32 (exact conversion).

All float16 values are exactly representable in f32.

Source

pub fn is_nan(self) -> bool

Returns true if this value is NaN.

Source

pub fn is_infinite(self) -> bool

Returns true if this value is positive or negative infinity.

Source

pub fn is_finite(self) -> bool

Returns true if this value is finite (not NaN or infinity).

Source

pub fn is_normal(self) -> bool

Returns true if this value is a normal number (not zero, subnormal, infinite, or NaN).

Source

pub fn is_subnormal(self) -> bool

Returns true if this value is subnormal.

Source

pub fn is_zero(self) -> bool

Returns true if this value is ±0.

Source

pub fn is_sign_negative(self) -> bool

Returns true if the sign bit is set (negative).

Source

pub fn is_sign_positive(self) -> bool

Returns true if the sign bit is not set (positive).

Source

pub fn eq_value(self, other: Self) -> bool

IEEE-754 numeric equality: NaN != NaN, +0 == -0.

Source

pub fn partial_cmp_value(self, other: Self) -> Option<Ordering>

IEEE-754 partial comparison: returns None if either value is NaN.

Source

pub fn total_cmp(self, other: Self) -> Ordering

Total ordering comparison (including NaN).

This matches the behavior of f32::total_cmp.

Source

pub fn add(self, rhs: Self) -> Self

Add two float16 values (via f32).

Source

pub fn sub(self, rhs: Self) -> Self

Subtract two float16 values (via f32).

Source

pub fn mul(self, rhs: Self) -> Self

Multiply two float16 values (via f32).

Source

pub fn div(self, rhs: Self) -> Self

Divide two float16 values (via f32).

Source

pub fn neg(self) -> Self

Negate this float16 value.

Source

pub fn abs(self) -> Self

Absolute value.

Trait Implementations§

Source§

impl Add for float16

Source§

type Output = float16

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self

Performs the + operation. Read more
Source§

impl Clone for float16

Source§

fn clone(&self) -> float16

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for float16

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for float16

Source§

fn default() -> float16

Returns the “default value” for a type. Read more
Source§

impl Display for float16

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Div for float16

Source§

type Output = float16

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Self) -> Self

Performs the / operation. Read more
Source§

impl ForyDefault for float16

Source§

fn fory_default() -> Self

Creates a default value for this type. Read more
Source§

impl Hash for float16

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Mul for float16

Source§

type Output = float16

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self

Performs the * operation. Read more
Source§

impl Neg for float16

Source§

type Output = float16

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl PartialEq for float16

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for float16

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serializer for float16

Source§

fn fory_write_data(&self, context: &mut WriteContext<'_>) -> Result<(), Error>

[USER IMPLEMENTATION REQUIRED] Serialize the type’s data to the buffer. Read more
Source§

fn fory_read_data(context: &mut ReadContext<'_>) -> Result<Self, Error>

[USER IMPLEMENTATION REQUIRED] Deserialize the type’s data from the buffer. Read more
Source§

fn fory_reserved_space() -> usize

Hint for buffer pre-allocation size. Read more
Source§

fn fory_get_type_id(_: &TypeResolver) -> Result<TypeId, Error>

Get the registered type ID from the type resolver. Read more
Source§

fn fory_type_id_dyn(&self, _: &TypeResolver) -> Result<TypeId, Error>

[USER IMPLEMENTATION REQUIRED] Get the runtime type ID for this instance. Read more
Source§

fn fory_static_type_id() -> TypeId

Get the static Fory type ID for this type. Read more
Source§

fn as_any(&self) -> &dyn Any

[USER IMPLEMENTATION REQUIRED] Downcast to &dyn Any for dynamic type checking. Read more
Source§

fn fory_write_type_info(context: &mut WriteContext<'_>) -> Result<(), Error>

Write type metadata to the buffer. Read more
Source§

fn fory_read_type_info(context: &mut ReadContext<'_>) -> Result<(), Error>

Read and validate type metadata from the buffer. Read more
Source§

fn fory_write( &self, context: &mut WriteContext<'_>, ref_mode: RefMode, write_type_info: bool, has_generics: bool, ) -> Result<(), Error>
where Self: Sized,

Entry point for serialization. Read more
Source§

fn fory_write_data_generic( &self, context: &mut WriteContext<'_>, has_generics: bool, ) -> Result<(), Error>

Write data with generic type parameter support. Read more
Source§

fn fory_read( context: &mut ReadContext<'_>, ref_mode: RefMode, read_type_info: bool, ) -> Result<Self, Error>
where Self: Sized + ForyDefault,

Entry point for deserialization. Read more
Source§

fn fory_read_with_type_info( context: &mut ReadContext<'_>, ref_mode: RefMode, type_info: Rc<TypeInfo>, ) -> Result<Self, Error>
where Self: Sized + ForyDefault,

Deserialize with pre-read type information. Read more
Source§

fn fory_is_option() -> bool
where Self: Sized,

Check if this type is Option<T>. Read more
Source§

fn fory_is_none(&self) -> bool

Check if this instance represents a None value. Read more
Source§

fn fory_is_polymorphic() -> bool
where Self: Sized,

Check if this type supports polymorphic serialization. Read more
Source§

fn fory_is_shared_ref() -> bool
where Self: Sized,

Check if this type is a shared reference (Rc/Arc). Read more
Source§

fn fory_is_wrapper_type() -> bool
where Self: Sized,

Source§

fn fory_get_type_info( type_resolver: &TypeResolver, ) -> Result<Rc<TypeInfo>, Error>
where Self: Sized,

Source§

fn fory_concrete_type_id(&self) -> TypeId

Get Rust’s std::any::TypeId for this instance. Read more
Source§

impl Sub for float16

Source§

type Output = float16

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self

Performs the - operation. Read more
Source§

impl Copy for float16

Source§

impl Eq for float16

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.