Added comparators to Fraction struct

This commit is contained in:
2024-07-26 01:24:52 +01:00
parent f64a82c538
commit 6d64f5ebac

View File

@@ -49,6 +49,19 @@ struct Fraction
{ {
} }
bool operator<(const Fraction other)
{
if (other.denominator == denominator)
return numerator < other.numerator;
// TODO: Is it better to use the GCD?
return (numerator * other.denominator) < (other.numerator * denominator);
}
bool operator==(const Fraction &other)
{
return numerator == other.numerator && denominator == other.denominator;
}
void simplify(void) void simplify(void)
{ {
// No-Op if already simplified // No-Op if already simplified