From 8621925e758d2df61da48cef22f1c298181f933f Mon Sep 17 00:00:00 2001 From: James Turner Date: Fri, 26 Jan 2018 11:29:18 +0000 Subject: [PATCH] Floating-point comparison helpers for SGMath Implemented using numeric_limits::epsilon and std::abs, fingers crossed this is sufficiently portable! --- simgear/math/SGMisc.hxx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/simgear/math/SGMisc.hxx b/simgear/math/SGMisc.hxx index 47e89f75..cd448b05 100644 --- a/simgear/math/SGMisc.hxx +++ b/simgear/math/SGMisc.hxx @@ -155,6 +155,12 @@ public: { return std::isnan(v); } + + static bool eq(const T& a, const T& b, const T& epsilon = SGLimits::epsilon()) + { return std::abs(a - b) < epsilon; } + + static bool neq(const T& a, const T& b, const T& epsilon = SGLimits::epsilon()) + { return !eq(a, b, epsilon); } }; #endif