aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2024-07-26 01:24:52 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2024-07-26 02:54:02 +0100
commit6d64f5ebacc9c4081624785298a4f4db142664d7 (patch)
tree52f1509fe81bf1e1ce6fb4f4dfef2323a0d7e377 /src/main.cpp
parentf64a82c538ecd4e6f0817e35eb5dee8af86815ce (diff)
downloadcw_tree-6d64f5ebacc9c4081624785298a4f4db142664d7.tar.gz
cw_tree-6d64f5ebacc9c4081624785298a4f4db142664d7.tar.bz2
cw_tree-6d64f5ebacc9c4081624785298a4f4db142664d7.zip
Added comparators to Fraction struct
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 222cab4..f490d41 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -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)
{
// No-Op if already simplified