From 13d590e5358fb0978b07e1293268b23ee912d825 Mon Sep 17 00:00:00 2001 From: Rene Milk <rene.milk@uni-muenster.de> Date: Thu, 5 Jan 2012 21:19:32 +0100 Subject: [PATCH] adds comparison with abs/rel tolerances --- stuff/math.hh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/stuff/math.hh b/stuff/math.hh index 34c6ff996..6bf14603b 100644 --- a/stuff/math.hh +++ b/stuff/math.hh @@ -143,6 +143,12 @@ T clamp(const T var, const T min, const T max) return ((var < min) ? min : (var > max) ? max : var); } +template <class T> +bool aboutEqual(const T& x, const T& y, T relative_tolerance = 1e-10, T absolute_tolerance = 1e-10) +{ + return (std::fabs(x - y) <= std::max(absolute_tolerance, relative_tolerance * std::max(std::fabs(x), std::fabs(y)))); +} + //! docme class MovingAverage { -- GitLab