aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtest18
-rw-r--r--zmodn.h6
2 files changed, 21 insertions, 3 deletions
diff --git a/test b/test
index 2930e89..3256a12 100755
--- a/test
+++ b/test
@@ -115,6 +115,24 @@ public:
115 assert_equal(n, Zmod<12>(4)); 115 assert_equal(n, Zmod<12>(4));
116 } 116 }
117}, 117},
118{
119 .name = "Multiplication overflow",
120 .f = []() {
121 Zmod<10> n = 8;
122 Zmod<10> m = 9;
123 auto prod = m * n;
124 assert_equal(prod.toint64(), 2);
125 }
126},
127{
128 .name = "Multiplication and assignment overflow",
129 .f = []() {
130 Zmod<10> n = 8;
131 Zmod<10> m = 9;
132 n *= m;
133 assert_equal(n.toint64(), 2);
134 }
135},
118}; 136};
119 137
120int main() { 138int main() {
diff --git a/zmodn.h b/zmodn.h
index 562aa22..f161ad1 100644
--- a/zmodn.h
+++ b/zmodn.h
@@ -17,9 +17,9 @@ public:
17 Zmod operator+(const Zmod& z) const { return int64 + z.int64; } 17 Zmod operator+(const Zmod& z) const { return int64 + z.int64; }
18 Zmod operator-(const Zmod& z) const { return int64 - z.int64; } 18 Zmod operator-(const Zmod& z) const { return int64 - z.int64; }
19 Zmod operator*(const Zmod& z) const { return int64 * z.int64; } 19 Zmod operator*(const Zmod& z) const { return int64 * z.int64; }
20 Zmod operator+=(const Zmod& z) { return int64 += z.int64; } 20 Zmod operator+=(const Zmod& z) { return (*this) = int64 + z.int64; }
21 Zmod operator-=(const Zmod& z) { return int64 -= z.int64; } 21 Zmod operator-=(const Zmod& z) { return (*this) = int64 - z.int64; }
22 Zmod operator*=(const Zmod& z) { return int64 *= z.int64; } 22 Zmod operator*=(const Zmod& z) { return (*this) = int64 * z.int64; }
23 23
24 bool operator==(const Zmod& z) const { return int64 == z.int64; } 24 bool operator==(const Zmod& z) const { return int64 == z.int64; }
25 bool operator!=(const Zmod& z) const { return int64 != z.int64; } 25 bool operator!=(const Zmod& z) const { return int64 != z.int64; }