]> git.proxmox.com Git - rustc.git/blob - vendor/crypto-bigint/src/uint/bit_not.rs
New upstream version 1.70.0+dfsg2
[rustc.git] / vendor / crypto-bigint / src / uint / bit_not.rs
1 //! [`UInt`] bitwise not operations.
2
3 use super::UInt;
4 use crate::{Limb, Wrapping};
5 use core::ops::Not;
6
7 impl<const LIMBS: usize> UInt<LIMBS> {
8 /// Computes bitwise `!a`.
9 #[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
23 impl<const LIMBS: usize> Not for UInt<LIMBS> {
24 type Output = Self;
25
26 fn not(self) -> <Self as Not>::Output {
27 (&self).not()
28 }
29 }
30
31 impl<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)]
40 mod 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 }