From 3595239f08f2bc1df32ef22ed6de9bde10ca3384 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 4 Jun 2007 01:35:20 +0000 Subject: Style cleanup, minor Matrix fixes, duplication validations, Pokemod methods git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@19 6ecfd1a5-f3ed-3746-8530-beee90d26b22 --- pokemod/Frac.cpp | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'pokemod/Frac.cpp') 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; -- cgit