From 5d02171a6f959ed57203bead8c03f3a003adc4a8 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 20 Mar 2018 13:32:24 +1100 Subject: [PATCH] maths: add relatively_equal comparator --- maths.hpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/maths.hpp b/maths.hpp index 0fb66b52..48a5edd7 100644 --- a/maths.hpp +++ b/maths.hpp @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * Copyright 2010-2014 Danny Robson + * Copyright 2010-2018 Danny Robson */ #ifndef __MATHS_HPP @@ -81,6 +81,13 @@ namespace util { /////////////////////////////////////////////////////////////////////////// // Comparisons inline bool + relatively_equal (float a, float b, float percentage) + { + return std::abs (1 - b / a ) < percentage; + } + + //------------------------------------------------------------------------- + inline bool almost_equal (float a, float b) { return ieee_single::almost_equal (a, b);