aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2024-07-26 01:40:21 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2024-07-26 02:54:02 +0100
commitcc51f78d107c1b4401b4092e30d8e35531d5b953 (patch)
treef1ce4bcda01af99263e6810919f00661a5736e87 /src
parent6d64f5ebacc9c4081624785298a4f4db142664d7 (diff)
downloadcw_tree-cc51f78d107c1b4401b4092e30d8e35531d5b953.tar.gz
cw_tree-cc51f78d107c1b4401b4092e30d8e35531d5b953.tar.bz2
cw_tree-cc51f78d107c1b4401b4092e30d8e35531d5b953.zip
Simplify at constructor in Fraction
Let's just deal with simplified stuff anyway?
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/main.cpp b/src/main.cpp
index f490d41..3613709 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -16,21 +16,19 @@
#include <cstdint>
#include <cstdio>
-#include <raylib.h>
#include <sstream>
#include <string>
#define MIN(A, B) ((A) < (B) ? (A) : (B))
#define MAX(A, B) ((A) > (B) ? (A) : (B))
-
typedef uint64_t word_t;
word_t gcd(word_t a, word_t b)
{
if (a == b)
return a;
- else if (a == 1 || b == 1)
+ else if (a <= 1 || b <= 1)
return 1;
for (word_t r = b % a; r != 0; b = a, a = r, r = b % a)
continue;
@@ -42,11 +40,11 @@ struct Fraction
word_t numerator, denominator;
bool is_simplified;
- Fraction(word_t numerator = 0, word_t denominator = 1,
- bool is_simplified = false)
- : numerator{numerator}, denominator{denominator},
- is_simplified{is_simplified}
+ Fraction(word_t numerator = 0, word_t denominator = 1)
+ : numerator{numerator}, denominator{denominator}, is_simplified{false}
{
+ // TODO: Figure out if this is a good idea, or simplifying afterwards
+ simplify();
}
bool operator<(const Fraction other)