fixed_wide_vectors/fixed_wide/src/wide.rs

31 lines
712 B
Rust
Raw Normal View History

2024-08-23 20:42:44 +00:00
use bnum::types::{I256,I512};
use fixed::{FixedI64,FixedI128};
use typenum::{Sum, Unsigned};
use typenum::consts::{U32,U64,U96,U128,U160,U192,U224,U256};
pub trait WideMul<Rhs=Self>{
type Output;
fn wide_mul(self,rhs:Rhs)->Self::Output;
}
pub struct Fixed<Int,Frac>{
bits:Int,
2024-08-23 20:00:22 +00:00
phantom:std::marker::PhantomData<Frac>,
}
2024-08-23 20:42:44 +00:00
pub type FixedI256<Frac>=Fixed<I256,Frac>;
pub type FixedI512<Frac>=Fixed<I512,Frac>;
impl<A,B> WideMul<FixedI128<B>> for FixedI128<A>
where
A:std::ops::Add<B>,
B:Unsigned,
{
type Output=FixedI256<Sum<A,B>>;
fn wide_mul(self,rhs:FixedI128<B>)->Self::Output{
FixedI256{
bits:I256::from(self.to_bits())*I256::from(rhs.to_bits()),
phantom:std::marker::PhantomData,
}
}
}