1
0
Fork 0

Update number/oint.cc

Signed-off-by: subcrip <contact@subc.rip>
This commit is contained in:
subcrip 2024-10-28 14:57:10 +08:00
parent 75a10aca7b
commit 5f5a22ec7a
1 changed files with 9 additions and 14 deletions

View File

@ -5,23 +5,18 @@ struct oint {
T val; T val;
oint() : carry(0), val(0) {} oint() : carry(0), val(0) {}
oint(const T& v) : carry(v > MAX), val(v % MDL) {} oint(const T& v) : carry(v > MAX), val(v % MDL) {}
oint(const bool& carry, const T& val) : carry(carry), val(val) {}
friend oint operator*(const oint& a, const oint& b) { friend oint operator*(const oint& a, const oint& b) {
oint res; return {
res.carry = a.carry | b.carry; a.carry or b.carry or a.val > MAX / b.val,
if (not res.carry and a.val > MAX / b.val) { (a.val * b.val) % MDL,
res.carry = 1; };
}
res.val = (a.val * b.val) % MDL;
return res;
} }
friend oint operator+(const oint& a, const oint& b) { friend oint operator+(const oint& a, const oint& b) {
oint res; return {
res.carry = a.carry | b.carry; a.carry or b.carry or a.val > MAX - b.val,
if (not res.carry and a.val > MAX - b.val) { (a.val + b.val) % MDL,
res.carry = 1; };
}
res.val = (a.val + b.val) % MDL;
return res;
} }
oint& operator+=(const oint& rhs) { return *this = *this + rhs; } oint& operator+=(const oint& rhs) { return *this = *this + rhs; }
oint& operator*=(const oint& rhs) { return *this = *this * rhs; } oint& operator*=(const oint& rhs) { return *this = *this * rhs; }