Implement NOT operator
Some checks failed
timw4mail/rusty-numbers/pipeline/head There was a failure building this commit

This commit is contained in:
Timothy Warren 2020-03-05 09:20:02 -05:00
parent f352c1aa4e
commit 437dcd34fb

View File

@ -210,6 +210,23 @@ impl Neg for BigInt {
}
}
impl Not for BigInt {
type Output = Self;
fn not(self) -> Self::Output {
let mut flipped: Vec<usize> = Vec::with_capacity(self.inner.len());
for (i, val) in self.inner.iter().enumerate() {
flipped[i] = val.reverse_bits();
}
BigInt {
sign: self.sign,
inner: flipped,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
@ -237,6 +254,12 @@ mod tests {
"least significant place should be MAX - 1"
);
assert_eq!(sum.inner[1], 1usize, "most significant place should be 1");
/* let a = BigInt::from(core::usize::MAX);
let b = BigInt::from(1usize);
let sum = a + b;
assert_eq!(sum.inner[0], 0usize);
assert_eq!(sum.inner[1], 1usize); */
}
#[test]