Add support for bitwise and and or on unsigned numbers.

This commit is contained in:
2019-05-27 21:41:05 -07:00
parent 83ed5bc0ba
commit 666378b14b
2 changed files with 23 additions and 0 deletions

View File

@@ -89,6 +89,28 @@ macro_rules! generate_base
$name{ value: x } $name{ value: x }
} }
} }
impl BitOr for $name {
type Output = $name;
fn bitor(mut self, rhs: Self) -> Self {
for (idx, val) in self.value.iter_mut().enumerate() {
*val |= rhs.value[idx];
}
self
}
}
impl BitAnd for $name {
type Output = $name;
fn bitand(mut self, rhs: Self) -> Self {
for (idx, val) in self.value.iter_mut().enumerate() {
*val &= rhs.value[idx];
}
self
}
}
} }
} }

View File

@@ -86,6 +86,7 @@ use std::ops::{Div,DivAssign};
use std::ops::{Rem,RemAssign}; use std::ops::{Rem,RemAssign};
use std::ops::{Shl,ShlAssign,Shr,ShrAssign}; use std::ops::{Shl,ShlAssign,Shr,ShrAssign};
use std::ops::{Sub,SubAssign}; use std::ops::{Sub,SubAssign};
use std::ops::{BitAnd,BitOr};
use quickcheck::{Arbitrary,Gen}; use quickcheck::{Arbitrary,Gen};