Skip to main content

bnum/bint/
ops.rs

1use crate::ExpType;
2use core::ops::{
3    Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, DivAssign,
4    Mul, MulAssign, Neg, Not, Rem, RemAssign, Shl, ShlAssign, Shr, ShrAssign, Sub, SubAssign,
5};
6
7macro_rules! ops {
8    ($BUint: ident, $BInt: ident, $Digit: ident) => {
9        impl<const N: usize> Neg for $BInt<N> {
10            type Output = Self;
11
12            #[inline]
13            fn neg(self) -> Self {
14                Self::neg(self)
15            }
16        }
17
18        impl<const N: usize> Neg for &$BInt<N> {
19            type Output = $BInt<N>;
20
21            #[inline]
22            fn neg(self) -> $BInt<N> {
23                $BInt::neg(*self)
24            }
25        }
26
27        impl<const N: usize> BitAnd for $BInt<N> {
28            type Output = Self;
29
30            #[inline]
31            fn bitand(self, rhs: Self) -> Self {
32                Self::bitand(self, rhs)
33            }
34        }
35
36        impl<const N: usize> BitOr for $BInt<N> {
37            type Output = Self;
38
39            #[inline]
40            fn bitor(self, rhs: Self) -> Self {
41                Self::bitor(self, rhs)
42            }
43        }
44
45        impl<const N: usize> BitXor for $BInt<N> {
46            type Output = Self;
47
48            #[inline]
49            fn bitxor(self, rhs: Self) -> Self {
50                Self::bitxor(self, rhs)
51            }
52        }
53
54        impl<const N: usize> Div for $BInt<N> {
55            type Output = Self;
56
57            #[inline]
58            fn div(self, rhs: Self) -> Self {
59                Self::div(self, rhs)
60            }
61        }
62
63        impl<const N: usize> Not for $BInt<N> {
64            type Output = Self;
65
66            fn not(self) -> Self {
67                Self::not(self)
68            }
69        }
70
71        impl<const N: usize> Rem for $BInt<N> {
72            type Output = Self;
73
74            #[inline]
75            fn rem(self, rhs: Self) -> Self {
76                Self::rem(self, rhs)
77            }
78        }
79
80        crate::int::ops::impls!($BInt, $BUint, $BInt);
81    };
82}
83
84#[cfg(test)]
85crate::test::all_digit_tests! {
86    use crate::test::{debug_skip, test_bignum, types::itest};
87    use core::ops::Neg;
88
89    test_bignum! {
90        function: <itest>::neg(a: itest),
91        skip: debug_skip!(a == itest::MIN)
92    }
93}
94
95crate::macro_impl!(ops);