crypto_bigint/uint/
bit_not.rs1use super::Uint;
4use crate::{Limb, Wrapping};
5use core::ops::Not;
6
7impl<const LIMBS: usize> Uint<LIMBS> {
8 #[inline(always)]
10 pub const fn not(&self) -> Self {
11 let mut limbs = [Limb::ZERO; LIMBS];
12 let mut i = 0;
13
14 while i < LIMBS {
15 limbs[i] = self.limbs[i].not();
16 i += 1;
17 }
18
19 Self { limbs }
20 }
21}
22
23impl<const LIMBS: usize> Not for Uint<LIMBS> {
24 type Output = Self;
25
26 fn not(self) -> Self {
27 Self::not(&self)
28 }
29}
30
31impl<const LIMBS: usize> Not for Wrapping<Uint<LIMBS>> {
32 type Output = Self;
33
34 fn not(self) -> <Self as Not>::Output {
35 Wrapping(self.0.not())
36 }
37}
38
39#[cfg(test)]
40mod tests {
41 use crate::U128;
42
43 #[test]
44 fn bitnot_ok() {
45 assert_eq!(U128::ZERO.not(), U128::MAX);
46 assert_eq!(U128::MAX.not(), U128::ZERO);
47 }
48}