1pub mod sub;
5pub mod add;
6pub mod mul;
7pub mod div;
8pub mod rem;
9pub mod cmp;
10
11use std::ops::{Neg, Not};
12use crate::ops::onforward_ref_unop;
13use std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign};
14use std::ops::{Shl, ShlAssign, Shr, ShrAssign};
15use crate::ops::{onforward_ref_binop, onforward_ref_op_assign};
16use crate::prim::{typ::*, mpz::*};
18
19onforward_ref_unop!{impl Neg, neg for mpz_s}
20
21impl<'a> Neg for &'a mpz_s {
23 type Output = <mpz_s as Neg>::Output;
24
25 #[inline]
27 fn neg(self) -> <mpz_s as Neg>::Output {
28 let mut t = mpz_s::init();
29 mpz_neg(&mut t, self);
30 t
31 }
32}
33
34onforward_ref_unop!{impl Not, not for mpz_s}
35
36impl<'a> Not for &'a mpz_s {
38 type Output = <mpz_s as Not>::Output;
39
40 #[inline]
42 fn not(self) -> <mpz_s as Not>::Output {
43 let mut t = mpz_s::init();
44 mpz_com(&mut t, self);
45 t
46 }
47}
48
49onforward_ref_binop!{impl BitAnd, bitand for mpz_s, mpz_s, mpz_s}
50
51impl<'a, 'b> BitAnd<&'b mpz_s> for &'a mpz_s {
53 type Output = <mpz_s as BitAnd<mpz_s>>::Output;
54
55 #[inline]
57 fn bitand(self, rhs: &'b mpz_s) -> <mpz_s as BitAnd<mpz_s>>::Output {
58 let mut t = mpz_s::init();
59 mpz_and(&mut t, self, rhs);
60 t
61 }
62}
63
64onforward_ref_op_assign!{impl BitAndAssign, bitand_assign for mpz_s, mpz_s}
65
66impl<'a> BitAndAssign<&'a Self> for mpz_s {
68 #[inline]
70 fn bitand_assign(&mut self, rhs: &'a Self) -> () {
71 self.set(&self.and(rhs));
72 }
73}
74
75onforward_ref_binop!{impl BitOr, bitor for mpz_s, mpz_s, mpz_s}
76
77impl<'a, 'b> BitOr<&'b mpz_s> for &'a mpz_s {
79 type Output = <mpz_s as BitOr<mpz_s>>::Output;
80
81 #[inline]
83 fn bitor(self, rhs: &'b mpz_s) -> <mpz_s as BitOr<mpz_s>>::Output {
84 let mut t = mpz_s::init();
85 mpz_ior(&mut t, self, rhs);
86 t
87 }
88}
89
90onforward_ref_op_assign!{impl BitOrAssign, bitor_assign for mpz_s, mpz_s}
91
92impl<'a> BitOrAssign<&'a Self> for mpz_s {
94 #[inline]
96 fn bitor_assign(&mut self, rhs: &'a Self) -> () {
97 self.set(&self.ior(rhs));
98 }
99}
100
101onforward_ref_binop!{impl BitXor, bitxor for mpz_s, mpz_s, mpz_s}
102
103impl<'a, 'b> BitXor<&'b mpz_s> for &'a mpz_s {
105 type Output = <mpz_s as BitXor<mpz_s>>::Output;
106
107 #[inline]
109 fn bitxor(self, rhs: &'b mpz_s) -> <mpz_s as BitXor<mpz_s>>::Output {
110 let mut t = mpz_s::init();
111 mpz_xor(&mut t, self, rhs);
112 t
113 }
114}
115
116onforward_ref_op_assign!{impl BitXorAssign, bitxor_assign for mpz_s, mpz_s}
117
118impl<'a> BitXorAssign<&'a Self> for mpz_s {
120 #[inline]
122 fn bitxor_assign(&mut self, rhs: &'a Self) -> () {
123 self.set(&self.xor(rhs));
124 }
125}
126
127onforward_ref_binop!{impl Shl, shl for mpz_s, mp_bitcnt_t, mpz_s}
128
129impl<'a, 'b> Shl<&'b mp_bitcnt_t> for &'a mpz_s {
131 type Output = <mpz_s as Shl<mp_bitcnt_t>>::Output;
132
133 #[inline]
135 fn shl(self, rhs: &'b mp_bitcnt_t) -> <mpz_s as Shl<mp_bitcnt_t>>::Output {
136 let mut t = mpz_s::init();
137 mpz_mul_2exp(&mut t, self, *rhs);
138 t
139 }
140}
141
142onforward_ref_op_assign!{impl ShlAssign, shl_assign for mpz_s, mp_bitcnt_t}
143
144impl<'a> ShlAssign<&'a mp_bitcnt_t> for mpz_s {
146 #[inline]
148 fn shl_assign(&mut self, rhs: &'a mp_bitcnt_t) -> () {
149 self.mul_2exp(*rhs);
150 }
151}
152
153onforward_ref_binop!{impl Shr, shr for mpz_s, mp_bitcnt_t, mpz_s}
154
155impl<'a, 'b> Shr<&'b mp_bitcnt_t> for &'a mpz_s {
157 type Output = <mpz_s as Shr<mp_bitcnt_t>>::Output;
158
159 #[inline]
161 fn shr(self, rhs: &'b mp_bitcnt_t) -> <mpz_s as Shr<mp_bitcnt_t>>::Output {
162 let mut t = mpz_s::init();
163 mpz_tdiv_q_2exp(&mut t, self, *rhs);
164 t
165 }
166}
167
168onforward_ref_op_assign!{impl ShrAssign, shr_assign for mpz_s, mp_bitcnt_t}
169
170impl<'a> ShrAssign<&'a mp_bitcnt_t> for mpz_s {
172 #[inline]
174 fn shr_assign(&mut self, rhs: &'a mp_bitcnt_t) -> () {
175 self.set(&self.tdiv_q_2exp(*rhs));
176 }
177}