use core::num::FpCategory;
use crate::inherent::AsReprInherent;
#[doc(hidden)]
#[non_exhaustive]
#[derive(Debug)]
pub enum Type {
F32,
F64,
}
pub unsafe trait Float: Copy {
const TYPE: Type;
}
unsafe impl<T> Float for T
where
T: AsReprInherent,
T::InherentRepr: Float,
{
const TYPE: Type = <T::InherentRepr as Float>::TYPE;
}
macro_rules! float {
($type:ty, $name:ident) => {
unsafe impl Float for $type {
const TYPE: Type = Type::$name;
}
};
}
float!(f32, F32);
float!(f64, F64);
pub const fn classify<T>(a: T) -> FpCategory
where
T: Float,
{
let a: *const T = &a;
match T::TYPE {
Type::F32 => unsafe { *a.cast::<f32>() }.classify(),
Type::F64 => unsafe { *a.cast::<f64>() }.classify(),
}
}