aboutsummaryrefslogtreecommitdiff
path: root/src/numerics.cpp
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2024-07-26 03:11:58 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2024-07-26 03:11:58 +0100
commit7f7a609d30dbfc9c119bd4567b5ee9b47434fa66 (patch)
tree010ccfdec2c794aeea3fe3fac8fa4e660ca300ac /src/numerics.cpp
parentf58a7e80ef503af58d8f7bfdc3d64e10717f9bf5 (diff)
downloadcw_tree-7f7a609d30dbfc9c119bd4567b5ee9b47434fa66.tar.gz
cw_tree-7f7a609d30dbfc9c119bd4567b5ee9b47434fa66.tar.bz2
cw_tree-7f7a609d30dbfc9c119bd4567b5ee9b47434fa66.zip
Introduce normalised value in fraction class
Bit of a cheat but it would allow us to do some interesting graphical stuff later.
Diffstat (limited to 'src/numerics.cpp')
-rw-r--r--src/numerics.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/numerics.cpp b/src/numerics.cpp
index ddf7187..833ac5f 100644
--- a/src/numerics.cpp
+++ b/src/numerics.cpp
@@ -19,13 +19,17 @@
#include <sstream>
Fraction::Fraction(word_t numerator, word_t denominator)
- : numerator{numerator}, denominator{denominator}
+ : numerator{numerator}, denominator{denominator},
+ norm{numerator / ((long double)denominator)}
{
word_t hcf = gcd(MIN(numerator, denominator), MAX(numerator, denominator));
numerator /= hcf;
denominator /= hcf;
}
+// floating point arithmetic inaccuracies blah blah blah better to use
+// simplified fractions here
+
bool Fraction::operator<(const Fraction other)
{
if (other.denominator == denominator)