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 / ONEuse zenpixels::F16Sample;
let x = F16Sample::ONE;
let _ = x.0; // inner field is private; use to_bits() or to_f32()Implementations§
Source§impl F16Sample
impl F16Sample
Sourcepub const MIN_POSITIVE: F16Sample
pub const MIN_POSITIVE: F16Sample
Smallest positive normal binary16 value (2^-14, 0x0400).
Sourcepub const NEG_INFINITY: F16Sample
pub const NEG_INFINITY: F16Sample
Negative infinity (-inf, 0xfc00).
Sourcepub const fn from_bits(bits: u16) -> F16Sample
pub const fn from_bits(bits: u16) -> F16Sample
Construct from raw IEEE 754 binary16 bits without modifying payloads.
Sourcepub const fn to_bits(self) -> u16
pub const fn to_bits(self) -> u16
Extract the raw IEEE 754 binary16 bits without modifying payloads.
Sourcepub const fn from_ne_bytes(bytes: [u8; 2]) -> F16Sample
pub const fn from_ne_bytes(bytes: [u8; 2]) -> F16Sample
Construct from native-endian bytes.
Sourcepub const fn to_ne_bytes(self) -> [u8; 2]
pub const fn to_ne_bytes(self) -> [u8; 2]
Return native-endian bytes.
Sourcepub const fn from_le_bytes(bytes: [u8; 2]) -> F16Sample
pub const fn from_le_bytes(bytes: [u8; 2]) -> F16Sample
Construct from little-endian bytes.
Sourcepub const fn to_le_bytes(self) -> [u8; 2]
pub const fn to_le_bytes(self) -> [u8; 2]
Return little-endian bytes.
Sourcepub const fn from_be_bytes(bytes: [u8; 2]) -> F16Sample
pub const fn from_be_bytes(bytes: [u8; 2]) -> F16Sample
Construct from big-endian bytes.
Sourcepub const fn to_be_bytes(self) -> [u8; 2]
pub const fn to_be_bytes(self) -> [u8; 2]
Return big-endian bytes.
Sourcepub const fn to_f32(self) -> f32
pub const fn to_f32(self) -> f32
Convert losslessly to f32, preserving sign, subnormals, infinities, and NaN payloads.
Sourcepub const fn from_f32(v: f32) -> F16Sample
pub const fn from_f32(v: f32) -> F16Sample
Convert f32 to F16Sample using IEEE 754 round-to-nearest-even.
- Values beyond
±65504.0saturate to±INFINITY. - Values below the smallest subnormal (
2^-24, ties to even/zero) underflow to±0.0. NaNinputs preserve sign and high-order payload bits with the quiet bit set.
Sourcepub const fn is_infinite(self) -> bool
pub const fn is_infinite(self) -> bool
Returns true if this value is +inf or -inf.
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_normal(self) -> bool
pub const fn is_normal(self) -> bool
Returns true if the number is neither zero, infinite, subnormal, nor NaN.
Sourcepub const fn is_sign_negative(self) -> bool
pub const fn is_sign_negative(self) -> bool
Returns true if the sign bit is set (including -0.0, -inf, and negative NaN).
Sourcepub const fn is_sign_positive(self) -> bool
pub const fn is_sign_positive(self) -> bool
Returns true if the sign bit is clear (including +0.0, +inf, and positive NaN).
Sourcepub fn total_cmp(&self, other: &F16Sample) -> Ordering
pub fn total_cmp(&self, other: &F16Sample) -> Ordering
IEEE 754 totalOrder comparison (-NaN < -inf < ... < -0.0 < +0.0 < ... < +inf < +NaN).
Sourcepub fn as_bits_slice(slice: &[F16Sample]) -> &[u16]
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).
Sourcepub fn as_bits_slice_mut(slice: &mut [F16Sample]) -> &mut [u16]
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).
Sourcepub fn from_bits_slice(slice: &[u16]) -> &[F16Sample]
pub fn from_bits_slice(slice: &[u16]) -> &[F16Sample]
Borrow a slice of raw u16 bit patterns as F16Sample without copying.
Sourcepub fn from_bits_slice_mut(slice: &mut [u16]) -> &mut [F16Sample]
pub fn from_bits_slice_mut(slice: &mut [u16]) -> &mut [F16Sample]
Mutably borrow a slice of raw u16 bit patterns as F16Sample without copying.
Trait Implementations§
impl Copy for F16Sample
Source§impl PartialOrd for F16Sample
impl PartialOrd for F16Sample
impl Pod for F16Sample
Source§impl StorageSample for F16Sample
impl StorageSample for F16Sample
Source§const SAMPLE_TYPE: SampleType = SampleType::F16
const SAMPLE_TYPE: SampleType = SampleType::F16
SampleType variant.Source§impl TypedElement for F16Sample
impl TypedElement for F16Sample
Source§fn matches_layout_with_packing(
layout: SampleLayout,
access: BitPackingAccess,
) -> bool
fn matches_layout_with_packing( layout: SampleLayout, access: BitPackingAccess, ) -> bool
layout under an explicit
BitPackingAccess policy.Source§fn matches_layout(layout: SampleLayout) -> bool
fn matches_layout(layout: SampleLayout) -> bool
layout under default
BitPackingAccess::Fail (requiring BitPacking::Full).Auto Trait Implementations§
impl Freeze for F16Sample
impl RefUnwindSafe for F16Sample
impl Send for F16Sample
impl Sync for F16Sample
impl Unpin for F16Sample
impl UnsafeUnpin for F16Sample
impl UnwindSafe for F16Sample
Blanket Implementations§
impl<T> AnyBitPattern for Twhere
T: Pod,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
§type Bits = T
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
fn is_valid_bit_pattern(_bits: &T) -> bool
bits
as &Self.