Skip to main content

F16Sample

Struct F16Sample 

Source
pub struct F16Sample(/* private fields */);
Expand description

IEEE 754 binary16 (half-precision float) interchange sample.

The internal representation is intentionally opaque (#[repr(transparent)] over a 16-bit IEEE 754 binary16 payload, 2-byte size and 2-byte alignment) so a future release can back it with core::primitive::f16 once Rust stabilizes native half-precision floats, without exposing raw integer field access or allowing accidental F16Sample(1) (6e-8 vs 1.0) bugs.

Every 16-bit pattern is a valid F16Sample (Zeroable + Pod, where all-zero bits represent +0.0), so slices and Vecs convert zero-copy to and from u16 (e.g. for magetypes::F16Convert), half::f16, or [u8] via [bytemuck] or the inherent as_bits_slice and vec_into_bits helpers.

ⓘ
use zenpixels::F16Sample;
let _ = F16Sample(1); // inner bits are private; use from_f32 / from_bits / ONE
ⓘ
use zenpixels::F16Sample;
let x = F16Sample::ONE;
let _ = x.0; // inner field is private; use to_bits() or to_f32()

Implementations§

Source§

impl F16Sample

Source

pub const ZERO: F16Sample

Positive zero (+0.0, 0x0000).

Source

pub const NEG_ZERO: F16Sample

Negative zero (-0.0, 0x8000).

Source

pub const ONE: F16Sample

Multiplicative identity (1.0, 0x3c00).

Source

pub const NEG_ONE: F16Sample

Negative one (-1.0, 0xbc00).

Source

pub const MIN: F16Sample

Smallest finite binary16 value (-65504.0, 0xfbff).

Source

pub const MAX: F16Sample

Largest finite binary16 value (65504.0, 0x7bff).

Source

pub const MIN_POSITIVE: F16Sample

Smallest positive normal binary16 value (2^-14, 0x0400).

Source

pub const EPSILON: F16Sample

Machine epsilon (2^-10, 0x1400).

Source

pub const INFINITY: F16Sample

Positive infinity (+inf, 0x7c00).

Source

pub const NEG_INFINITY: F16Sample

Negative infinity (-inf, 0xfc00).

Source

pub const NAN: F16Sample

Canonical quiet NaN (0x7e00).

Source

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

Construct from raw IEEE 754 binary16 bits without modifying payloads.

Source

pub const fn to_bits(self) -> u16

Extract the raw IEEE 754 binary16 bits without modifying payloads.

Source

pub const fn from_ne_bytes(bytes: [u8; 2]) -> F16Sample

Construct from native-endian bytes.

Source

pub const fn to_ne_bytes(self) -> [u8; 2]

Return native-endian bytes.

Source

pub const fn from_le_bytes(bytes: [u8; 2]) -> F16Sample

Construct from little-endian bytes.

Source

pub const fn to_le_bytes(self) -> [u8; 2]

Return little-endian bytes.

Source

pub const fn from_be_bytes(bytes: [u8; 2]) -> F16Sample

Construct from big-endian bytes.

Source

pub const fn to_be_bytes(self) -> [u8; 2]

Return big-endian bytes.

Source

pub const fn to_f32(self) -> f32

Convert losslessly to f32, preserving sign, subnormals, infinities, and NaN payloads.

Source

pub const fn from_f32(v: f32) -> F16Sample

Convert f32 to F16Sample using IEEE 754 round-to-nearest-even.

  • Values beyond ±65504.0 saturate to ±INFINITY.
  • Values below the smallest subnormal (2^-24, ties to even/zero) underflow to ±0.0.
  • NaN inputs preserve sign and high-order payload bits with the quiet bit set.
Source

pub const fn is_nan(self) -> bool

Returns true if this value is NaN.

Source

pub const fn is_infinite(self) -> bool

Returns true if this value is +inf or -inf.

Source

pub const fn is_finite(self) -> bool

Returns true if this number is neither infinite nor NaN.

Source

pub const fn is_subnormal(self) -> bool

Returns true if the number is subnormal.

Source

pub const fn is_normal(self) -> bool

Returns true if the number is neither zero, infinite, subnormal, nor NaN.

Source

pub const fn is_sign_negative(self) -> bool

Returns true if the sign bit is set (including -0.0, -inf, and negative NaN).

Source

pub const fn is_sign_positive(self) -> bool

Returns true if the sign bit is clear (including +0.0, +inf, and positive NaN).

Source

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

IEEE 754 totalOrder comparison (-NaN < -inf < ... < -0.0 < +0.0 < ... < +inf < +NaN).

Source

pub fn as_bits_slice(slice: &[F16Sample]) -> &[u16]

Borrow a slice of F16Sample as raw u16 bit patterns without copying (e.g. for magetypes::F16Convert::f16_to_f32_slice).

Source

pub fn as_bits_slice_mut(slice: &mut [F16Sample]) -> &mut [u16]

Mutably borrow a slice of F16Sample as raw u16 bit patterns without copying (e.g. for magetypes::F16Convert::f32_to_f16_slice).

Source

pub fn from_bits_slice(slice: &[u16]) -> &[F16Sample]

Borrow a slice of raw u16 bit patterns as F16Sample without copying.

Source

pub fn from_bits_slice_mut(slice: &mut [u16]) -> &mut [F16Sample]

Mutably borrow a slice of raw u16 bit patterns as F16Sample without copying.

Source

pub fn vec_into_bits(vec: Vec<F16Sample>) -> Vec<u16>

Convert an owned Vec<F16Sample> into Vec<u16> without reallocating or copying.

Source

pub fn vec_from_bits(vec: Vec<u16>) -> Vec<F16Sample>

Convert an owned Vec<u16> of IEEE 754 binary16 bits into Vec<F16Sample> without reallocating or copying.

Trait Implementations§

Source§

impl Clone for F16Sample

Source§

fn clone(&self) -> F16Sample

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for F16Sample

Source§

impl Debug for F16Sample

Source§

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

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

impl Default for F16Sample

Source§

fn default() -> F16Sample

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

impl Display for F16Sample

Source§

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

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

impl PartialEq for F16Sample

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for F16Sample

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 Pod for F16Sample

Source§

impl StorageSample for F16Sample

Source§

const SAMPLE_TYPE: SampleType = SampleType::F16

Corresponding SampleType variant.
Source§

impl TypedElement for F16Sample

Source§

fn matches_layout_with_packing( layout: SampleLayout, access: BitPackingAccess, ) -> bool

Whether this element type is semantically compatible with layout under an explicit BitPackingAccess policy.
Source§

fn matches_layout(layout: SampleLayout) -> bool

Whether this element type is semantically compatible with layout under default BitPackingAccess::Fail (requiring BitPacking::Full).
Source§

impl Zeroable for F16Sample

§

fn zeroed() -> Self

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
§

impl<T> AnyBitPattern for T
where T: Pod,

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
§

impl<T> CheckedBitPattern for T
where T: AnyBitPattern,

§

type Bits = T

Self must have the same layout as the specified Bits except for the possible invalid bit patterns being checked during is_valid_bit_pattern.
§

fn is_valid_bit_pattern(_bits: &T) -> bool

If this function returns true, then it must be valid to reinterpret bits as &Self.
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.

§

impl<T> NoUninit for T
where T: Pod,

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.