Add support for differing types in almost_equal
This commit is contained in:
parent
1627754b6a
commit
64dd72db85
12
maths.hpp
12
maths.hpp
@ -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>
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user