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 #[allow(clippy::needless_borrow)]
27 fn not(self) -> <Self as Not>::Output {
28 (&self).not()
29 }
30}
31
32impl<const LIMBS: usize> Not for Wrapping<Uint<LIMBS>> {
33 type Output = Self;
34
35 fn not(self) -> <Self as Not>::Output {
36 Wrapping(self.0.not())
37 }
38}
39
40#[cfg(test)]
41mod tests {
42 use crate::U128;
43
44 #[test]
45 fn bitnot_ok() {
46 assert_eq!(U128::ZERO.not(), U128::MAX);
47 assert_eq!(U128::MAX.not(), U128::ZERO);
48 }
49}