From 5f5a22ec7a0b513d2ca12ddbb426ca3a1a7f4d5c Mon Sep 17 00:00:00 2001 From: subcrip Date: Mon, 28 Oct 2024 14:57:10 +0800 Subject: [PATCH] Update number/oint.cc Signed-off-by: subcrip --- number/oint.cc | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/number/oint.cc b/number/oint.cc index 63050f4..916e38a 100644 --- a/number/oint.cc +++ b/number/oint.cc @@ -5,23 +5,18 @@ struct oint { T val; oint() : carry(0), val(0) {} 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) { - oint res; - res.carry = a.carry | b.carry; - if (not res.carry and a.val > MAX / b.val) { - res.carry = 1; - } - res.val = (a.val * b.val) % MDL; - return res; + return { + a.carry or b.carry or a.val > MAX / b.val, + (a.val * b.val) % MDL, + }; } friend oint operator+(const oint& a, const oint& b) { - oint res; - res.carry = a.carry | b.carry; - if (not res.carry and a.val > MAX - b.val) { - res.carry = 1; - } - res.val = (a.val + b.val) % MDL; - return res; + return { + a.carry or b.carry or a.val > MAX - b.val, + (a.val + b.val) % MDL, + }; } oint& operator+=(const oint& rhs) { return *this = *this + rhs; } oint& operator*=(const oint& rhs) { return *this = *this * rhs; }