fix/
util.rs

1use typenum::NInt;
2
3use crate::typenum::{IsLess, NonZero, Unsigned, U10, U20};
4use crate::Fix;
5
6/// Domain specific extensions to the `Fix` type as it's used in this project.
7pub trait FixExt: Sized {
8    /// This precision's equivalent of 1.
9    fn one() -> Self;
10    fn zero() -> Self;
11}
12
13impl<Bits, Exp> FixExt for Fix<Bits, U10, NInt<Exp>>
14where
15    Exp: Unsigned + NonZero + IsLess<U20>,
16    Bits: From<u64>,
17{
18    fn one() -> Fix<Bits, U10, NInt<Exp>> {
19        Fix::new(U10::to_u64().pow(Exp::to_u32()).into())
20    }
21
22    fn zero() -> Self {
23        Fix::new(0.into())
24    }
25}