use fixed::{
traits::{Fixed, FixedSigned},
types::{U0F128, U6F122},
};
pub const fn fixed_one<Val>() -> Val
where
Val: Fixed,
{
match Val::TRY_ONE {
Some(one) => one,
None => panic!("fixed number can not represent 1"),
}
}
pub const fn fixed_neg_one<Val>() -> Val
where
Val: FixedSigned,
{
match Val::TRY_NEG_ONE {
Some(one) => one,
None => panic!("fixed number can not represent 1"),
}
}
pub(crate) const fn fixed_bits<Val>() -> u32
where
Val: Fixed,
{
(Val::INT_NBITS + Val::FRAC_NBITS) as u32
}
const FRAC_180_PI: U6F122 =
U6F122::lit("57.295779513082320876798154814105170332405472466564321549160243861");
const FRAC_PI_180: U0F128 =
U0F128::lit("0.0174532925199432957692369076848861271344287188854172545609719144");
pub fn rad_to_deg<Val>(r: Val) -> Val
where
Val: Fixed,
{
r * Val::from_fixed(FRAC_180_PI)
}
pub fn deg_to_rad<Val>(d: Val) -> Val
where
Val: Fixed,
{
d * Val::from_fixed(FRAC_PI_180)
}