Skip to main content

crypto_bigint/int/
bit_not.rs

1//! [`Int`] bitwise NOT operations.
2
3use core::ops::Not;
4
5use crate::{Uint, Wrapping};
6
7use super::Int;
8
9impl<const LIMBS: usize> Int<LIMBS> {
10    /// Computes bitwise `!a`.
11    #[inline(always)]
12    #[must_use]
13    pub const fn not(&self) -> Self {
14        Self(Uint::not(&self.0))
15    }
16}
17
18impl<const LIMBS: usize> Not for Int<LIMBS> {
19    type Output = Self;
20
21    fn not(self) -> Self {
22        Self::not(&self)
23    }
24}
25
26impl<const LIMBS: usize> Not for Wrapping<Int<LIMBS>> {
27    type Output = Self;
28
29    fn not(self) -> <Self as Not>::Output {
30        Wrapping(self.0.not())
31    }
32}
33
34#[cfg(test)]
35mod tests {
36    use crate::I128;
37
38    #[test]
39    fn bitnot_ok() {
40        assert_eq!(I128::ZERO.not(), I128::MINUS_ONE);
41        assert_eq!(I128::MAX.not(), I128::MIN);
42    }
43}