more operators
This commit is contained in:
parent
e002fd91d7
commit
12693fc20f
2 changed files with 28 additions and 7 deletions
|
|
@ -19,13 +19,13 @@ class mint {
|
|||
[[nodiscard]] constexpr explicit mint(T t) : value{t % M} {}
|
||||
[[nodiscard]] constexpr explicit operator T() const noexcept { return value; }
|
||||
|
||||
[[nodiscard]] constexpr mint<T, M> operator+(
|
||||
mint const other) const noexcept {
|
||||
[[nodiscard]] constexpr mint operator+(mint const other) const noexcept {
|
||||
T result{add(static_cast<T>(other.get()))};
|
||||
|
||||
return mint<T, M>{result};
|
||||
}
|
||||
[[nodiscard]] constexpr mint& operator+=(mint const other) const noexcept {
|
||||
|
||||
constexpr mint& operator+=(mint const other) const noexcept {
|
||||
value += other.value;
|
||||
|
||||
return *this;
|
||||
|
|
@ -44,7 +44,7 @@ class mint {
|
|||
return mint<T, M>{result};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr mint& operator*=(mint const other) noexcept {
|
||||
constexpr mint& operator*=(mint const other) noexcept {
|
||||
value *= other.value;
|
||||
|
||||
return *this;
|
||||
|
|
@ -61,7 +61,8 @@ class mint {
|
|||
|
||||
return mint<T, M>{result};
|
||||
}
|
||||
[[nodiscard]] constexpr mint& operator/=(mint const other) noexcept {
|
||||
|
||||
constexpr mint& operator/=(mint const other) noexcept {
|
||||
if constexpr (other.get() == 0) {
|
||||
static_assert(false, "Cannot divide by 0");
|
||||
} else if (other.get() == 0) {
|
||||
|
|
@ -79,12 +80,30 @@ class mint {
|
|||
return mint<T, M>{result};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr mint& operator%=(mint const other) const noexcept {
|
||||
constexpr mint& operator%=(mint const other) const noexcept {
|
||||
value %= other.value;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr mint operator-() const noexcept {
|
||||
return mint<T, M>{M - get()};
|
||||
}
|
||||
|
||||
constexpr mint operator++() noexcept {
|
||||
value += 1;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr mint operator++(int) noexcept {
|
||||
auto _this = *this;
|
||||
|
||||
value += 1;
|
||||
|
||||
return _this;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr T get() const noexcept { return value; }
|
||||
|
||||
[[nodiscard]] constexpr bool operator==(mint const other) const noexcept {
|
||||
|
|
|
|||
|
|
@ -30,7 +30,9 @@ int main() {
|
|||
// cout << (mint<int, 4>{5} + mint<int, 4>{7});
|
||||
// cout << pow(mint<int, 5>{4}, 5);
|
||||
|
||||
cout << (pow(mint<int>{5}, 5));
|
||||
// cout << to_string(pow(mint<int>{5}, 5));
|
||||
|
||||
mint<int> x{5};
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue