WideMul trait
This commit is contained in:
parent
713b68adef
commit
276602e5f3
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -58,6 +58,7 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"bnum",
|
"bnum",
|
||||||
"fixed",
|
"fixed",
|
||||||
|
"typenum",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
1
fixed_wide/Cargo.lock
generated
1
fixed_wide/Cargo.lock
generated
@ -50,6 +50,7 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"bnum",
|
"bnum",
|
||||||
"fixed",
|
"fixed",
|
||||||
|
"typenum",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -6,3 +6,4 @@ edition = "2021"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
bnum = "0.11.0"
|
bnum = "0.11.0"
|
||||||
fixed = "1.28.0"
|
fixed = "1.28.0"
|
||||||
|
typenum = "1.17.0"
|
||||||
|
@ -1,4 +1,30 @@
|
|||||||
pub struct Fixed<I,Frac>{
|
use bnum::types::{I256,I512};
|
||||||
bits:I,
|
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,
|
||||||
phantom:std::marker::PhantomData<Frac>,
|
phantom:std::marker::PhantomData<Frac>,
|
||||||
}
|
}
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user