From d1dd06aa0a7fbf3aea51a602af1558022c9a2d3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 6 Apr 2012 01:56:14 +0200 Subject: [PATCH] Ability to explicitly specify precision for floating-point equality. --- src/Math/TypeTraits.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Math/TypeTraits.h b/src/Math/TypeTraits.h index 4a269fb24..6f7050df2 100644 --- a/src/Math/TypeTraits.h +++ b/src/Math/TypeTraits.h @@ -21,6 +21,16 @@ #include +/** @brief Precision when testing floats for equality */ +#ifndef FLOAT_EQUALITY_PRECISION +#define FLOAT_EQUALITY_PRECISION 1.0e-6 +#endif + +/** @brief Precision when testing doubles for equality */ +#ifndef DOUBLE_EQUALITY_PRECISION +#define DOUBLE_EQUALITY_PRECISION 1.0e-12 +#endif + namespace Magnum { namespace Math { /** @@ -99,10 +109,10 @@ template struct _TypeTraitsFloatingPoint { } }; template<> struct TypeTraits: public _TypeTraitsFloatingPoint { - constexpr inline static float epsilon() { return 1.0e-6f; } + constexpr inline static float epsilon() { return FLOAT_EQUALITY_PRECISION; } }; template<> struct TypeTraits: public _TypeTraitsFloatingPoint { - constexpr inline static double epsilon() { return 1.0e-12; } + constexpr inline static double epsilon() { return DOUBLE_EQUALITY_PRECISION; } }; #endif