#include "num.h"
Num::Num(int value, int modulo) {
if (modulo == 0) {
this->value = value;
} else {
this->value = value % modulo;
}
this->modulo = modulo;
}
Num Num::operator*(int num) const {
return {this->modulo == 0 ? (this->value * num) : ((this->value * num) % this->modulo), this->modulo};
}
Num &Num::operator*=(int num) {
this->value = this->modulo == 0 ? (this->value * num) : ((this->value * num) % this->modulo);
return *this;
}
Num Num::operator+(int num) const {
return {this->modulo == 0 ? (this->value + num) : ((this->value + num) % this->modulo), this->modulo};
}
Num &Num::operator+=(int num) {
this->value = this->modulo == 0 ? (this->value + num) : ((this->value + num) % this->modulo);
return *this;
}
Num Num::operator-(int num) const {
return {this->modulo == 0 ? (this->value - num) : ((this->value - num) % this->modulo), this->modulo};
}
Num &Num::operator-=(int num) {
this->value = this->modulo == 0 ? (this->value - num) : ((this->value - num) % this->modulo);
return *this;
}
Num &Num::operator=(const Num &other) = default;
Num Num::operator-(const Num &other) {
return *this - other.value;
}
Num Num::operator+(const Num &other) {
return *this + other.value;
}
Num Num::operator*(const Num &other) {
return *this * other.value;
}
Num &Num::operator+=(const Num &other) {
*this += other.value;
return *this;
}
Num &Num::operator*=(const Num &other) {
*this *= other.value;
return *this;
}
Num &Num::operator-=(const Num &other) {
*this -= other.value;
return *this;
}