From 9e81d4b6c33f065aabe3162f77cb995bee503156 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 24 Feb 2012 23:53:34 +0100 Subject: [PATCH] Fixed awesome mistake in Math::TypeTraits. Epsilon value for integral types should be 1, not 0. Updated documentation and test to reflect the change. --- src/Math/Test/TypeTraitsTest.cpp | 3 +-- src/Math/TypeTraits.h | 5 +++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Math/Test/TypeTraitsTest.cpp b/src/Math/Test/TypeTraitsTest.cpp index 6f0b2791a..1be3e6da8 100644 --- a/src/Math/Test/TypeTraitsTest.cpp +++ b/src/Math/Test/TypeTraitsTest.cpp @@ -42,8 +42,7 @@ void TypeTraitsTest::equalsFloatingPoint() { } template void TypeTraitsTest::_equalsIntegral() { - QVERIFY(TypeTraits::equals(1, 1+TypeTraits::epsilon())); - QVERIFY(!TypeTraits::equals(1, 2)); + QVERIFY(!TypeTraits::equals(1, 1+TypeTraits::epsilon())); } template void TypeTraitsTest::_equalsFloatingPoint() { diff --git a/src/Math/TypeTraits.h b/src/Math/TypeTraits.h index 512668143..4a269fb24 100644 --- a/src/Math/TypeTraits.h +++ b/src/Math/TypeTraits.h @@ -44,7 +44,8 @@ template struct TypeTraits { /** * @brief Epsilon value for fuzzy compare * - * Returns 0 for integer types and reasonably small value for + * Returns minimal difference between numbers to be considered + * inequal. Returns 1 for integer types and reasonably small value for * floating-point types. */ constexpr inline static T epsilon(); @@ -69,7 +70,7 @@ template struct TypeTraits { #ifndef DOXYGEN_GENERATING_OUTPUT template struct _TypeTraitsIntegral { - constexpr inline static T epsilon() { return 0; } + constexpr inline static T epsilon() { return 1; } inline constexpr static bool equals(T a, T b) { return a == b;