use bnum::cast::As; use bnum::types::{I256,I512}; use fixed::{FixedI64,FixedI128}; use typenum::{Sum, Unsigned}; use typenum::consts::{U32,U64,U96,U128,U160,U192,U224,U256}; #[derive(Clone,Copy,Debug)] pub struct Fixed{ bits:Int, phantom:std::marker::PhantomData, } pub type FixedI256=Fixed; pub type FixedI512=Fixed; impl+std::ops::Shl,FracDst:Unsigned> From for Fixed{ fn from(value:i128)->Self{ Self{ bits:Int::from(value)< PartialEq for Fixed{ fn eq(&self,other:&Self)->bool{ self.bits==other.bits } } impl Eq for Fixed{} pub trait WideMul{ type Output; fn wide_mul(self,rhs:Rhs)->Self::Output; } //going wide from foreign fixed type impl WideMul> for FixedI128 where A:std::ops::Add, B:Unsigned, { type Output=FixedI256>; fn wide_mul(self,rhs:FixedI128)->Self::Output{ FixedI256{ bits:I256::from(self.to_bits())*I256::from(rhs.to_bits()), phantom:std::marker::PhantomData, } } } //going wider native impl WideMul> for FixedI256 where A:std::ops::Add, B:Unsigned, { type Output=FixedI512>; fn wide_mul(self,rhs:FixedI256)->Self::Output{ FixedI512{ bits:self.bits.as_::()*rhs.bits.as_::(), phantom:std::marker::PhantomData, } } }