summaryrefslogtreecommitdiffstats
path: root/pokemod/Frac.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'pokemod/Frac.cpp')
-rw-r--r--pokemod/Frac.cpp15
1 files changed, 4 insertions, 11 deletions
diff --git a/pokemod/Frac.cpp b/pokemod/Frac.cpp
index 7d919f1b..9341e6a5 100644
--- a/pokemod/Frac.cpp
+++ b/pokemod/Frac.cpp
@@ -24,9 +24,9 @@
#include "Frac.h"
PokeGen::PokeMod::Frac::Frac(const bool i) :
- num(1),
- denom(1),
- improper(i)
+ num(1),
+ denom(1),
+ improper(i)
{
Log("Frac: Initializing", PM_DEBUG_DEBUG);
}
@@ -49,9 +49,7 @@ void PokeGen::PokeMod::Frac::ImportIni(Ini &ini)
void PokeGen::PokeMod::Frac::ExportIni(std::ofstream &fout, const String &val)
{
Log(String("Frac Export: Starting %u/%u as %s", num, denom, val.c_str()), PM_DEBUG_INFO);
- // Reduce fraction before storing
Reduce();
- // Declare the elements
Ini exFrac(val);
exFrac.AddField("num", num);
exFrac.AddField("denom", denom);
@@ -76,7 +74,6 @@ void PokeGen::PokeMod::Frac::Set(const unsigned n, const unsigned d, const bool
void PokeGen::PokeMod::Frac::SetNum(const unsigned n)
{
- // Make sure the numerator is less than the denominator if proper
if ((n <= denom) || improper)
{
Log(String("Frac: Setting numerator to %u (%u/%u)", n, n, denom), PM_DEBUG_DEBUG);
@@ -88,7 +85,6 @@ void PokeGen::PokeMod::Frac::SetNum(const unsigned n)
void PokeGen::PokeMod::Frac::SetDenom(const unsigned d)
{
- // Make sure the denominator isn't 0
if (d)
{
Log(String("Frac: Setting denominator to %u", d), PM_DEBUG_DEBUG);
@@ -96,7 +92,6 @@ void PokeGen::PokeMod::Frac::SetDenom(const unsigned d)
}
else
Log("Frac: Attempting to set denominator to 0", PM_DEBUG_DEBUG);
- // Set the numerator to less than the denominator if proper
if ((num <= denom) && !improper)
{
Log(String("Frac: Setting numerator to 1 after denominator reset to (%u)", d), PM_DEBUG_DEBUG);
@@ -138,10 +133,8 @@ float PokeGen::PokeMod::Frac::GetValue() const
void PokeGen::PokeMod::Frac::Reduce()
{
Log(String("Frac: Reducing %u/%u", num, denom), PM_DEBUG_DEBUG);
- // Iterate until i is greater than the square root on num
- for (unsigned i = 2; i * i <= num; ++i)
+ for (unsigned i = 2; i <= (num < denom ? num : denom); ++i)
{
- // Keep iterating while i is a factor of both
while (!((num % i) || (denom % i)))
{
num /= i;