cubecl_common/float/
fp6.rs

1use bytemuck::{Pod, Zeroable};
2
3/// A 6-bit floating point type with 2 exponent bits and 3 mantissa bits.
4///
5/// [`Minifloat`]: https://en.wikipedia.org/wiki/Minifloat
6#[allow(non_camel_case_types)]
7#[repr(transparent)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9#[derive(Clone, Copy, Default, Zeroable, Pod, PartialEq, PartialOrd)]
10pub struct e2m3(u8);
11
12/// A 6-bit floating point type with 3 exponent bits and 2 mantissa bits.
13///
14/// [`Minifloat`]: https://en.wikipedia.org/wiki/Minifloat
15#[allow(non_camel_case_types)]
16#[repr(transparent)]
17#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
18#[derive(Clone, Copy, Default, Zeroable, Pod, PartialEq, PartialOrd)]
19pub struct e3m2(u8);
20
21impl e2m3 {
22    /// Maximum representable value
23    pub const MAX: f64 = 3.75;
24    /// Minimum representable value
25    pub const MIN: f64 = -3.75;
26}
27
28impl e3m2 {
29    /// Maximum representable value
30    pub const MAX: f64 = 14.0;
31    /// Minimum representable value
32    pub const MIN: f64 = -14.0;
33}