1
0
Fork 0

Update number/fractional.cc

Signed-off-by: subcrip <contact@subc.rip>
This commit is contained in:
subcrip 2024-11-26 20:05:15 +00:00
parent 2c5c036fdf
commit f7205eb816
1 changed files with 2 additions and 1 deletions

View File

@ -3,7 +3,7 @@ struct fractional {
T p, q;
inline void reduce(void) {
if (q < 0) p = -p, q = -q;
if (p == 0) q = 1; else { T g = mygcd(p, q); p /= g; q /= g; }
if (p == 0) q = 1; else { T g = mygcd(abs(p), abs(q)); p /= g; q /= g; }
}
fractional(void) : p(0), q(1) {}
template <typename U>
@ -25,4 +25,5 @@ struct fractional {
friend inline bool operator>=(const fractional& lhs, const fractional& rhs) { return not (lhs < rhs); }
friend inline bool operator>(const fractional& lhs, const fractional& rhs) { return lhs >= rhs and lhs != rhs; }
friend inline bool operator<=(const fractional& lhs, const fractional& rhs) { return lhs < rhs or lhs == rhs; }
friend inline ostream& operator<<(ostream& out, const fractional& x) { return out << x.p << '/' << x.q; }
};