From 64dd72db85279a822df1dadf002fbe2ad4e586c5 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Fri, 20 Apr 2012 18:02:54 +1000 Subject: [PATCH] Add support for differing types in almost_equal --- maths.hpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/maths.hpp b/maths.hpp index 1ff22c54..5d83533f 100644 --- a/maths.hpp +++ b/maths.hpp @@ -22,6 +22,7 @@ #include "annotations.hpp" +#include template T @@ -62,13 +63,24 @@ almost_equal (const T &a, const T &b) template -bool +typename std::enable_if< + std::is_arithmetic::value && std::is_arithmetic::value, + bool +>::type almost_equal (const Ta &a, const Tb &b) { return almost_equal (static_cast(a), static_cast(b)); } +template +typename std::enable_if< + !std::is_arithmetic::value || !std::is_arithmetic::value, + bool +>::type +almost_equal (const Ta &a, const Tb &b) + { return a == b; } + const double PI = 3.141592653589793238462643; inline double