This commit is contained in:
Eric Mertens
2022-11-18 14:50:42 -08:00
parent 4d4dfb4424
commit 8f772d85b2
5 changed files with 239 additions and 3 deletions

View File

@@ -21,6 +21,12 @@ public:
return {value + rhs.value};
}
auto operator+=(ZMod const& rhs) -> ZMod & {
value += rhs.value;
mpz_mod_ui(this->value.get_mpz_t(), value.get_mpz_t(), Mod);
return *this;
}
auto operator-() const -> ZMod {
return {-value};
}
@@ -29,10 +35,22 @@ public:
return {value - rhs.value};
}
auto operator-=(ZMod const& rhs) -> ZMod & {
value -= rhs.value;
mpz_mod_ui(value.get_mpz_t(), value.get_mpz_t(), Mod);
return *this;
}
auto operator*(ZMod const& rhs) const -> ZMod {
return {value * rhs.value};
}
auto operator*=(ZMod const& rhs) -> ZMod & {
value -= rhs.value;
mpz_mod_ui(value.get_mpz_t(), value.get_mpz_t(), Mod);
return *this;
}
auto inverse() const -> ZMod {
mpz_class m{Mod};
ZMod result;
@@ -47,4 +65,4 @@ public:
}
#endif
#endif