Sun, 31 Aug 2014 14:38:53 +0300
- ring finder now also tries scaling by 10 (3.4, 6.4 -> 34, 64), fixed floating point math argghhhhhhhh
src/basics.h | file | annotate | diff | comparison | revisions | |
src/macros.h | file | annotate | diff | comparison | revisions | |
src/ringFinder.cc | file | annotate | diff | comparison | revisions |
--- a/src/basics.h Sun Aug 31 03:10:51 2014 +0300 +++ b/src/basics.h Sun Aug 31 14:38:53 2014 +0300 @@ -241,13 +241,13 @@ template<typename T> inline bool IsZero (T a) { - return Abs<T> (a) < 0.0001; + return Abs<T> (a) < 0.00001; } template<typename T> inline bool IsIntegral (T a) { - return IsZero (a - int (a)); + return (Abs (a - floor(a)) < 0.00001) or (Abs (a - ceil(a)) < 0.00001); } template<typename T>
--- a/src/macros.h Sun Aug 31 03:10:51 2014 +0300 +++ b/src/macros.h Sun Aug 31 14:38:53 2014 +0300 @@ -71,6 +71,8 @@ // ============================================================================= // #define elif(A) else if (A) +#define unless(A) if (not (A)) +#define until(A) while (not (A)) // ============================================================================= //
--- a/src/ringFinder.cc Sun Aug 31 03:10:51 2014 +0300 +++ b/src/ringFinder.cc Sun Aug 31 14:38:53 2014 +0300 @@ -135,11 +135,18 @@ double r0f = r0 / scale; double r1f = r1 / scale; - if (qFuzzyCompare (floor (r0f), r0f) and qFuzzyCompare (floor (r1f), r1f)) + if (IsIntegral (r0f) and IsIntegral (r1f)) { r0 = r0f; r1 = r1f; } + // If the numbers are both at most one-decimal fractions, we can use a scale of 10 + elif (IsIntegral (r0 * 10) and IsIntegral (r1 * 10)) + { + scale = 0.1; + r0 *= 10; + r1 *= 10; + } } else {