use crate::int::Sealed as _;
use crate::{Denominator, Integer, NotOne, Numerator, Recip, Q};
use core::ops::{Div, Rem};
use typenum::{Mod, Quot};
pub trait PrivateF64Helper {
const F64: f64;
}
impl<N> PrivateF64Helper for Q<N>
where
N: Numerator,
{
const F64: f64 = N::F64;
}
impl<N, D> PrivateF64Helper for Q<N, D>
where
N: Numerator<D> + Div<D> + Rem<D>,
D: Denominator + NotOne + Numerator,
Quot<N, D>: Integer,
Mod<N, D>: Numerator<D>,
Q<Mod<N, D>, D>: Recip,
<Q<Mod<N, D>, D> as Recip>::Output: PrivateF64Helper,
{
const F64: f64 =
Quot::<N, D>::F64 + 1_f64 / <<Q<Mod<N, D>, D> as Recip>::Output as PrivateF64Helper>::F64;
}
pub trait Sealed: PrivateF64Helper {
const F64: f64 = <Self as PrivateF64Helper>::F64;
}
impl<N, D> Sealed for Q<N, D>
where
Self: PrivateF64Helper,
N: Numerator<D>,
D: Denominator,
{
}
pub trait Rational: 'static + Default + Copy + Sealed {
const F64: f64 = <Self as PrivateF64Helper>::F64;
}
impl<N, D> Rational for Q<N, D>
where
Self: Sealed,
N: Numerator<D>,
D: Denominator,
{
}