X-Git-Url: https://git.libre-soc.org/?p=vector-math.git;a=blobdiff_plain;f=src%2Fieee754.rs;h=3d70468a8e438490a836e6787e097412ad2a847d;hp=6f9fea7359f868e466a45ea84603a02c98a1c20a;hb=ba67f8a36240e8ee2e95bb79aa7a58ae77577197;hpb=ad217eb300ff1d610689c9ebe5b06e94b659a508 diff --git a/src/ieee754.rs b/src/ieee754.rs index 6f9fea7..3d70468 100644 --- a/src/ieee754.rs +++ b/src/ieee754.rs @@ -1,8 +1,4 @@ -use crate::{ - f16::F16, - scalar::Scalar, - traits::{Float, Make}, -}; +use crate::f16::F16; mod sealed { use crate::f16::F16; @@ -13,9 +9,9 @@ mod sealed { impl Sealed for f64 {} } -pub trait FloatEncoding: - sealed::Sealed + Copy + 'static + Send + Sync + Float + Make -{ +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; @@ -37,11 +33,15 @@ pub trait FloatEncoding: 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 _; @@ -69,6 +69,8 @@ macro_rules! impl_float_encoding { 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; } @@ -76,6 +78,8 @@ impl_float_encoding! { 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; } @@ -83,6 +87,8 @@ impl_float_encoding! { 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; }