Skip to main content

crypto_bigint/int/
bit_not.rs

1//! [`Int`] bitwise NOT operations.
2
3use core::ops::Not;
4
5use crate::Uint;
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
26#[cfg(test)]
27mod tests {
28    use crate::I128;
29
30    #[test]
31    fn bitnot_ok() {
32        assert_eq!(I128::ZERO.not(), I128::MINUS_ONE);
33        assert_eq!(I128::MAX.not(), I128::MIN);
34    }
35}