summaryrefslogtreecommitdiff
path: root/osframework/source/SexyAppFramework/Ratio.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'osframework/source/SexyAppFramework/Ratio.cpp')
-rw-r--r--osframework/source/SexyAppFramework/Ratio.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/osframework/source/SexyAppFramework/Ratio.cpp b/osframework/source/SexyAppFramework/Ratio.cpp
new file mode 100644
index 0000000..059085d
--- /dev/null
+++ b/osframework/source/SexyAppFramework/Ratio.cpp
@@ -0,0 +1,36 @@
+
+#include "Ratio.h"
+
+namespace Sexy
+{
+
+ Ratio::Ratio()
+ : mNumerator(1)
+ , mDenominator(1)
+ {
+ }
+
+ Ratio::Ratio(int theNumerator, int theDenominator)
+ {
+ Set(theNumerator, theDenominator);
+ }
+
+ void Ratio::Set(int theNumerator, int theDenominator)
+ {
+ // find the greatest-common-denominator of theNumerator and theDenominator.
+ int t;
+ int a = theNumerator;
+ int b = theDenominator;
+ while (b != 0)
+ {
+ t = b;
+ b = a % b;
+ a = t;
+ }
+
+ // divide by the g-c-d to reduce mNumerator/mDenominator to lowest terms.
+ mNumerator = theNumerator/a;
+ mDenominator = theDenominator/a;
+ }
+
+}