1#[cfg(feature = "num-bigint")]
2mod bigint {
3
4 use crate::ops::{Operation, Commutative, Identity, Invertible};
5 use crate::ops::{Add, Mul};
6 use num_bigint::{BigInt, BigUint};
7
8 impl Operation<BigInt> for Add {
9 fn combine(&self, a: &BigInt, b: &BigInt) -> BigInt {
11 a + b
12 }
13 fn combine_mut(&self, a: &mut BigInt, b: &BigInt) {
15 *a += b;
16 }
17 fn combine_mut2(&self, a: &BigInt, b: &mut BigInt) {
19 *b += a;
20 }
21 fn combine_left(&self, a: BigInt, b: &BigInt) -> BigInt {
23 a + b
24 }
25 fn combine_right(&self, a: &BigInt, b: BigInt) -> BigInt {
27 a + b
28 }
29 fn combine_both(&self, a: BigInt, b: BigInt) -> BigInt {
31 a + b
32 }
33 }
34 impl Commutative<BigInt> for Add {}
35 impl Identity<BigInt> for Add {
36 fn identity(&self) -> BigInt {
38 0.into()
39 }
40 }
41 impl Invertible<BigInt> for Add {
42 fn uncombine(&self, a: &mut BigInt, b: &BigInt) {
44 *a -= b;
45 }
46 }
47
48 impl Operation<BigUint> for Add {
49 fn combine(&self, a: &BigUint, b: &BigUint) -> BigUint {
51 a + b
52 }
53 fn combine_mut(&self, a: &mut BigUint, b: &BigUint) {
55 *a += b;
56 }
57 fn combine_mut2(&self, a: &BigUint, b: &mut BigUint) {
59 *b += a;
60 }
61 fn combine_left(&self, a: BigUint, b: &BigUint) -> BigUint {
63 a + b
64 }
65 fn combine_right(&self, a: &BigUint, b: BigUint) -> BigUint {
67 a + b
68 }
69 fn combine_both(&self, a: BigUint, b: BigUint) -> BigUint {
71 a + b
72 }
73 }
74 impl Commutative<BigUint> for Add {}
75 impl Identity<BigUint> for Add {
76 fn identity(&self) -> BigUint {
78 0u32.into()
79 }
80 }
81
82
83 impl Operation<BigInt> for Mul {
84 fn combine(&self, a: &BigInt, b: &BigInt) -> BigInt {
86 a * b
87 }
88 fn combine_mut(&self, a: &mut BigInt, b: &BigInt) {
90 *a *= b;
91 }
92 fn combine_mut2(&self, a: &BigInt, b: &mut BigInt) {
94 *b *= a;
95 }
96 fn combine_left(&self, a: BigInt, b: &BigInt) -> BigInt {
98 a * b
99 }
100 fn combine_right(&self, a: &BigInt, b: BigInt) -> BigInt {
102 a * b
103 }
104 fn combine_both(&self, a: BigInt, b: BigInt) -> BigInt {
106 a * b
107 }
108 }
109 impl Commutative<BigInt> for Mul {}
110 impl Identity<BigInt> for Mul {
111 fn identity(&self) -> BigInt {
113 1.into()
114 }
115 }
116
117 impl Operation<BigUint> for Mul {
118 fn combine(&self, a: &BigUint, b: &BigUint) -> BigUint {
120 a * b
121 }
122 fn combine_mut(&self, a: &mut BigUint, b: &BigUint) {
124 *a *= b;
125 }
126 fn combine_mut2(&self, a: &BigUint, b: &mut BigUint) {
128 *b *= a;
129 }
130 fn combine_left(&self, a: BigUint, b: &BigUint) -> BigUint {
132 a * b
133 }
134 fn combine_right(&self, a: &BigUint, b: BigUint) -> BigUint {
136 a * b
137 }
138 fn combine_both(&self, a: BigUint, b: BigUint) -> BigUint {
140 a * b
141 }
142 }
143 impl Commutative<BigUint> for Mul {}
144 impl Identity<BigUint> for Mul {
145 fn identity(&self) -> BigUint {
147 1u32.into()
148 }
149 }
150}
151