macro_rules! impl_float_storage {
($(#[$meta:meta])* $name:ident, $bits:ty) => {
$(#[$meta])*
#[derive(Default, Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[repr(transparent)]
pub struct $name(
/// Raw storage bits, preserved without conversion or validation.
pub $bits,
);
impl $name {
pub const fn from_bits(bits: $bits) -> Self {
Self(bits)
}
pub const fn to_bits(self) -> $bits {
self.0
}
}
};
}
impl_float_storage!(
f8e4m3,
u8
);
impl_float_storage!(
f8e5m2,
u8
);
impl_float_storage!(
f8ue8m0,
u8
);
impl_float_storage!(
f8ue5m3,
u8
);
impl_float_storage!(
f6e2m3,
u8
);
impl_float_storage!(
f6e3m2,
u8
);
impl_float_storage!(
f4e2m1,
u8
);