use crate::*;
#[cfg(feature = "f64_to_f32")]
use num_traits::ToPrimitive;
macro_rules! impl_primitive {
($($bty:ty, $lty:ty)*) => {
$(
impl BitDouble for $bty {
type Double = $lty;
fn double(&self) -> Self::Double {
Self::Double::from(*self)
}
}
impl BitHalf for $lty {
type Half = $bty;
fn half(&self) -> Option<Self::Half> {
Self::Half::try_from(*self).ok()
}
}
)*
};
}
impl_primitive! {
u8, u16
u16, u32
u32, u64
u64, u128
i8, i16
i16, i32
i32, i64
i64, i128
}
impl BitDouble for f32 {
type Double = f64;
fn double(&self) -> Self::Double {
(*self).into()
}
}
#[cfg(feature = "f64_to_f32")]
impl BitHalf for f64 {
type Half = f32;
fn half(&self) -> Option<Self::Half> {
self.to_f32()
}
}