From cc51f78d107c1b4401b4092e30d8e35531d5b953 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Fri, 26 Jul 2024 01:40:21 +0100 Subject: Simplify at constructor in Fraction Let's just deal with simplified stuff anyway? --- src/main.cpp | 12 +++++------- 1 file 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 #include -#include #include #include #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) -- cgit v1.2.3-13-gbd6f