fixed: implement shift operators
This commit is contained in:
parent
7a5406e769
commit
79ab26f118
@ -91,3 +91,31 @@ impl_assign_operator!( Fixed, BitOrAssign, bitor_assign );
|
|||||||
impl_operator!( Fixed, BitOr, bitor, Self );
|
impl_operator!( Fixed, BitOr, bitor, Self );
|
||||||
impl_assign_operator!( Fixed, BitXorAssign, bitxor_assign );
|
impl_assign_operator!( Fixed, BitXorAssign, bitxor_assign );
|
||||||
impl_operator!( Fixed, BitXor, bitxor, Self );
|
impl_operator!( Fixed, BitXor, bitxor, Self );
|
||||||
|
|
||||||
|
macro_rules! impl_shift_operator {
|
||||||
|
( $struct: ident, $trait: ident, $method: ident, $output: ty ) => {
|
||||||
|
impl<const CHUNKS:usize,Frac> core::ops::$trait<u32> for $struct<CHUNKS,Frac>{
|
||||||
|
type Output = $output;
|
||||||
|
|
||||||
|
fn $method(self, other: u32) -> Self::Output {
|
||||||
|
Self {
|
||||||
|
bits:self.bits.$method(other),
|
||||||
|
frac:PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
macro_rules! impl_shift_assign_operator {
|
||||||
|
( $struct: ident, $trait: ident, $method: ident ) => {
|
||||||
|
impl<const CHUNKS:usize,Frac> core::ops::$trait<u32> for $struct<CHUNKS,Frac>{
|
||||||
|
fn $method(&mut self, other: u32) {
|
||||||
|
self.bits.$method(other);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
impl_shift_assign_operator!( Fixed, ShlAssign, shl_assign );
|
||||||
|
impl_shift_operator!( Fixed, Shl, shl, Self );
|
||||||
|
impl_shift_assign_operator!( Fixed, ShrAssign, shr_assign );
|
||||||
|
impl_shift_operator!( Fixed, Shr, shr, Self );
|
||||||
|
@ -25,6 +25,12 @@ fn you_can_add_numbers(){
|
|||||||
assert_eq!(a+a,Planar64Wide3::from((3i128*2).pow(4)*2))
|
assert_eq!(a+a,Planar64Wide3::from((3i128*2).pow(4)*2))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn you_can_shr_numbers(){
|
||||||
|
let a=Planar64::from(4);
|
||||||
|
assert_eq!(a>>1,Planar64::from(2))
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn wide_vec3(){
|
fn wide_vec3(){
|
||||||
let v=Vector3::from_value(Planar64::from(3));
|
let v=Vector3::from_value(Planar64::from(3));
|
||||||
|
Loading…
Reference in New Issue
Block a user