Browse Source

Fixed awesome mistake in Math::TypeTraits.

Epsilon value for integral types should be 1, not 0. Updated
documentation and test to reflect the change.
vectorfields
Vladimír Vondruš 14 years ago
parent
commit
9e81d4b6c3
  1. 3
      src/Math/Test/TypeTraitsTest.cpp
  2. 5
      src/Math/TypeTraits.h

3
src/Math/Test/TypeTraitsTest.cpp

@ -42,8 +42,7 @@ void TypeTraitsTest::equalsFloatingPoint() {
} }
template<class T> void TypeTraitsTest::_equalsIntegral() { template<class T> void TypeTraitsTest::_equalsIntegral() {
QVERIFY(TypeTraits<T>::equals(1, 1+TypeTraits<T>::epsilon())); QVERIFY(!TypeTraits<T>::equals(1, 1+TypeTraits<T>::epsilon()));
QVERIFY(!TypeTraits<T>::equals(1, 2));
} }
template<class T> void TypeTraitsTest::_equalsFloatingPoint() { template<class T> void TypeTraitsTest::_equalsFloatingPoint() {

5
src/Math/TypeTraits.h

@ -44,7 +44,8 @@ template<class T> struct TypeTraits {
/** /**
* @brief Epsilon value for fuzzy compare * @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. * floating-point types.
*/ */
constexpr inline static T epsilon(); constexpr inline static T epsilon();
@ -69,7 +70,7 @@ template<class T> struct TypeTraits {
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
template<class T> struct _TypeTraitsIntegral { template<class T> 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) { inline constexpr static bool equals(T a, T b) {
return a == b; return a == b;

Loading…
Cancel
Save