Skip to main content

fix/
util.rs

1use crate::typenum::consts::Z0;
2use crate::typenum::{Integer, IsLess, B1, U10};
3use crate::{Fix, FromUnsigned, Pow};
4
5/// Domain specific extensions to the `Fix` type as it's used in this project.
6pub trait FixExt: Sized {
7    /// This precision's equivalent of 1.
8    fn one() -> Self;
9}
10
11impl<Bits, Exp> FixExt for Fix<Bits, U10, Exp>
12where
13    Bits: FromUnsigned + Pow,
14    Exp: Integer + IsLess<Z0, Output = B1>,
15{
16    fn one() -> Self {
17        let base = Bits::from_unsigned::<U10>();
18        Fix::new(base.pow(Exp::to_i32().unsigned_abs()))
19    }
20}