From 0bdea2b7148e57b22db66afb7d7b854e737f3fda Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Wed, 23 Nov 2016 13:43:08 +0300 Subject: [PATCH] core: fix absdiff (non-optimized, fp) to prevent "-0" results --- modules/core/src/arithm_core.hpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/modules/core/src/arithm_core.hpp b/modules/core/src/arithm_core.hpp index b92d47a817..99b564cf74 100644 --- a/modules/core/src/arithm_core.hpp +++ b/modules/core/src/arithm_core.hpp @@ -97,6 +97,22 @@ template struct OpAbsDiff T operator()(T a, T b) const { return a > b ? a - b : b - a; } }; +// specializations to prevent "-0" results +template<> struct OpAbsDiff +{ + typedef float type1; + typedef float type2; + typedef float rtype; + float operator()(float a, float b) const { return std::abs(a - b); } +}; +template<> struct OpAbsDiff +{ + typedef double type1; + typedef double type2; + typedef double rtype; + double operator()(double a, double b) const { return std::abs(a - b); } +}; + template struct OpAnd { typedef T type1;