00001
00002 #ifndef TESTTOOLS_FLOATASSERT_H
00003 #define TESTTOOLS_FLOATASSERT_H
00004
00005 #include <iostream>
00006 #include <cassert>
00007 #include <cfloat>
00008 #include <cmath>
00009
00010 #undef NDEBUG
00011
00012 namespace Athena_test {
00013 inline
00014 bool floatEQ(float lhs, float rhs) {
00015 return fabs(lhs-rhs)<=FLT_EPSILON;
00016 }
00017 inline
00018 bool floatNEQ(float lhs, float rhs) {
00019 return fabs(lhs-rhs)>FLT_EPSILON;
00020 }
00021
00022 inline
00023 bool isEqual (double x1, double x2, double thresh = 1e-6)
00024 {
00025 double den = std::abs(x1+x2);
00026 if (den < thresh) return true;
00027 if (std::abs (x1-x2) / den < thresh)
00028 return true;
00029 std::cout << "Match failure: " << x1 << " " << x2 << "\n";
00030 return false;
00031 }
00032
00033 }
00034
00035 #define FLOAT_NEQassert( LHS, RHS ) assert(Athena_test::floatNEQ(LHS, RHS));
00036 #define FLOAT_EQassert( LHS, RHS ) assert(Athena_test::floatEQ(LHS, RHS));
00037
00038 #endif