-use crate::{
- f16::F16,
- scalar::Scalar,
- traits::{Float, Make},
-};
+use crate::f16::F16;
mod sealed {
use crate::f16::F16;
impl Sealed for f64 {}
}
-pub trait FloatEncoding:
- sealed::Sealed + Copy + 'static + Send + Sync + Float + Make<Context = Scalar>
-{
+pub trait FloatEncoding: sealed::Sealed + Copy + 'static + Send + Sync {
+ type BitsType;
+ type SignedBitsType;
const EXPONENT_BIAS_UNSIGNED: Self::BitsType;
const EXPONENT_BIAS_SIGNED: Self::SignedBitsType;
const SIGN_FIELD_WIDTH: Self::BitsType;
macro_rules! impl_float_encoding {
(
impl FloatEncoding for $float:ident {
+ type BitsType = $bits_type:ident;
+ type SignedBitsType = $signed_bits_type:ident;
const EXPONENT_FIELD_WIDTH: u32 = $exponent_field_width:literal;
const MANTISSA_FIELD_WIDTH: u32 = $mantissa_field_width:literal;
}
) => {
impl FloatEncoding for $float {
+ type BitsType = $bits_type;
+ type SignedBitsType = $signed_bits_type;
const EXPONENT_BIAS_UNSIGNED: Self::BitsType =
(1 << (Self::EXPONENT_FIELD_WIDTH - 1)) - 1;
const EXPONENT_BIAS_SIGNED: Self::SignedBitsType = Self::EXPONENT_BIAS_UNSIGNED as _;
impl_float_encoding! {
impl FloatEncoding for F16 {
+ type BitsType = u16;
+ type SignedBitsType = i16;
const EXPONENT_FIELD_WIDTH: u32 = 5;
const MANTISSA_FIELD_WIDTH: u32 = 10;
}
impl_float_encoding! {
impl FloatEncoding for f32 {
+ type BitsType = u32;
+ type SignedBitsType = i32;
const EXPONENT_FIELD_WIDTH: u32 = 8;
const MANTISSA_FIELD_WIDTH: u32 = 23;
}
impl_float_encoding! {
impl FloatEncoding for f64 {
+ type BitsType = u64;
+ type SignedBitsType = i64;
const EXPONENT_FIELD_WIDTH: u32 = 11;
const MANTISSA_FIELD_WIDTH: u32 = 52;
}