From: vbd Date: Thu, 23 Aug 2007 14:21:58 +0000 (+0000) Subject: staffan : X-Git-Tag: trio_trio_coupling~65 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b1c01f2140e0c657531ed23bf6194c7e47f6b4e4;p=tools%2Fmedcoupling.git staffan : * added epsilonEqualRelative for better equality checing of doubles --- diff --git a/src/INTERP_KERNEL/VectorUtils.hxx b/src/INTERP_KERNEL/VectorUtils.hxx index f8e58d9d8..a85525de0 100644 --- a/src/INTERP_KERNEL/VectorUtils.hxx +++ b/src/INTERP_KERNEL/VectorUtils.hxx @@ -55,9 +55,22 @@ namespace INTERP_UTILS inline bool epsilonEqual(const double x, const double y, const double errTol = 1.0e-12) { - return std::abs(x - y) < errTol; + return std::abs(x - y) <= errTol; + } + + inline bool epsilonEqualRelative(const double x, const double y, const double relTol = 1.0e-6, const double absTol = 1.0e-17) + { + // necessary for comparing values close to zero + // in order to avoid division + if(std::abs(x - y) < absTol) + { + return true; + } + + const double relError = std::abs((x - y) / std::max(x, y)); + + return relError <= relTol; } - };