Add support for differing types in almost_equal

This commit is contained in:
Danny Robson 2012-04-20 18:02:54 +10:00
parent 1627754b6a
commit 64dd72db85

View File

@ -22,6 +22,7 @@
#include "annotations.hpp"
#include <type_traits>
template <typename T>
T
@ -62,13 +63,24 @@ almost_equal (const T &a, const T &b)
template <typename Ta, typename Tb>
bool
typename std::enable_if<
std::is_arithmetic<Ta>::value && std::is_arithmetic<Tb>::value,
bool
>::type
almost_equal (const Ta &a, const Tb &b) {
return almost_equal <decltype(a + b)> (static_cast<decltype(a + b)>(a),
static_cast<decltype(a + b)>(b));
}
template <typename Ta, typename Tb>
typename std::enable_if<
!std::is_arithmetic<Ta>::value || !std::is_arithmetic<Tb>::value,
bool
>::type
almost_equal (const Ta &a, const Tb &b)
{ return a == b; }
const double PI = 3.141592653589793238462643;
inline double