Add support for differing types in almost_equal
This commit is contained in:
parent
1627754b6a
commit
64dd72db85
14
maths.hpp
14
maths.hpp
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include "annotations.hpp"
|
#include "annotations.hpp"
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T
|
T
|
||||||
@ -62,13 +63,24 @@ almost_equal (const T &a, const T &b)
|
|||||||
|
|
||||||
|
|
||||||
template <typename Ta, typename Tb>
|
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) {
|
almost_equal (const Ta &a, const Tb &b) {
|
||||||
return almost_equal <decltype(a + b)> (static_cast<decltype(a + b)>(a),
|
return almost_equal <decltype(a + b)> (static_cast<decltype(a + b)>(a),
|
||||||
static_cast<decltype(a + b)>(b));
|
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;
|
const double PI = 3.141592653589793238462643;
|
||||||
|
|
||||||
inline double
|
inline double
|
||||||
|
Loading…
Reference in New Issue
Block a user