From 1d9a39f79293857542438650678e6b281437d2e8 Mon Sep 17 00:00:00 2001 From: peri4 Date: Mon, 10 Jan 2022 17:10:41 +0300 Subject: [PATCH] piCompare --- libs/main/core/pibase.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libs/main/core/pibase.h b/libs/main/core/pibase.h index 8c978f93..de83702b 100644 --- a/libs/main/core/pibase.h +++ b/libs/main/core/pibase.h @@ -31,6 +31,7 @@ #include "pip_export.h" #include "pip_defs.h" #include "string.h" +#include //! Meta-information section for any entity. //! Parsing by \a pip_cmg and can be accessed by \a PICodeInfo. @@ -355,6 +356,17 @@ inline bool piCompareBinary(const void * f, const void * s, size_t size) { return true; } +/*! @brief Function for compare two numeric values with epsilon + * \details Example:\n \snippet piincludes.cpp compare +* There are some macros: +* - \c piComparef for "float" +* - \c piCompared for "double" +*/ +template +inline bool piCompare(const T & a, const T & b, const T & epsilon = std::numeric_limits::epsilon()) { + return std::abs(a - b) <= epsilon; +} + /*! @brief Templated function return round of float falue * \details Round is the nearest integer value \n * There are some macros: @@ -558,6 +570,8 @@ template<> inline uint piHash(const ldouble & v) {return piHashData((const uchar #define piRoundf piRound #define piRoundd piRound +#define piComparef piCompare +#define piCompared piCompare #define piFloorf piFloor #define piFloord piFloor #define piCeilf piCeil