pub struct F4E2M1x2(/* private fields */);Expand description
Two F4E2M1 values packed into a single byte.
The lower nibble (bits 3:0) holds the first value and the upper nibble
(bits 7:4) holds the second value. This layout matches NVIDIA’s
__nv_fp4x2_e2m1 format.
§Examples
use float4::{F4E2M1, F4E2M1x2};
let lo = F4E2M1::from_f64(1.5);
let hi = F4E2M1::from_f64(-2.0);
let packed = F4E2M1x2::new(lo, hi);
assert_eq!(packed.lo().to_f64(), 1.5);
assert_eq!(packed.hi().to_f64(), -2.0);Implementations§
Source§impl F4E2M1x2
impl F4E2M1x2
Sourcepub const fn new(lo: F4E2M1, hi: F4E2M1) -> Self
pub const fn new(lo: F4E2M1, hi: F4E2M1) -> Self
Packs two F4E2M1 values into a single byte.
lo occupies bits 3:0 and hi occupies bits 7:4.
Sourcepub fn from_f32_pair(a: f32, b: f32) -> Self
pub fn from_f32_pair(a: f32, b: f32) -> Self
Creates a packed pair by converting two f32 values to F4E2M1.
Each value is independently rounded to the nearest representable F4E2M1 value using round-to-nearest-even.
§Examples
use float4::F4E2M1x2;
let packed = F4E2M1x2::from_f32_pair(1.5, -2.0);
assert_eq!(packed.lo().to_f64(), 1.5);
assert_eq!(packed.hi().to_f64(), -2.0);Sourcepub fn to_f32_pair(self) -> (f32, f32)
pub fn to_f32_pair(self) -> (f32, f32)
Extracts both values as an (f32, f32) pair.
§Examples
use float4::F4E2M1x2;
let packed = F4E2M1x2::from_f32_pair(3.0, -0.5);
let (a, b) = packed.to_f32_pair();
assert_eq!(a, 3.0);
assert_eq!(b, -0.5);Trait Implementations§
impl Copy for F4E2M1x2
impl Eq for F4E2M1x2
impl StructuralPartialEq for F4E2M1x2
Auto Trait Implementations§
impl Freeze for F4E2M1x2
impl RefUnwindSafe for F4E2M1x2
impl Send for F4E2M1x2
impl Sync for F4E2M1x2
impl Unpin for F4E2M1x2
impl UnsafeUnpin for F4E2M1x2
impl UnwindSafe for F4E2M1x2
Blanket Implementations§
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
Mutably borrows from an owned value. Read more