From 3ca2c3acbc5e3f06b5513bf7e5515e7dd6b6de0c Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Thu, 6 May 2021 18:30:42 +0300 Subject: [PATCH] Simplification --- src/Common/NaNUtils.h | 47 +++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 31 deletions(-) diff --git a/src/Common/NaNUtils.h b/src/Common/NaNUtils.h index 3b393fad41e..1c5a619e919 100644 --- a/src/Common/NaNUtils.h +++ b/src/Common/NaNUtils.h @@ -4,48 +4,33 @@ #include #include -#include - - -/// To be sure, that this function is zero-cost for non-floating point types. -template -inline std::enable_if_t, bool> isNaN(T x) -{ - return std::isnan(x); -} template -inline std::enable_if_t, bool> isNaN(T) +inline bool isNaN(T x) { - return false; + /// To be sure, that this function is zero-cost for non-floating point types. + if constexpr (std::is_floating_point_v) + return std::isnan(x); + else + return false; } -template -inline std::enable_if_t, bool> isFinite(T x) -{ - return std::isfinite(x); -} template -inline std::enable_if_t, bool> isFinite(T) +inline bool isFinite(T x) { - return true; + if constexpr (std::is_floating_point_v) + return std::isfinite(x); + else + return true; } -template -std::enable_if_t, T> NaNOrZero() -{ - return std::numeric_limits::quiet_NaN(); -} template -std::enable_if_t, T> NaNOrZero() +T NaNOrZero() { - return T{0}; -} - -template -std::enable_if_t && !is_integer_v, T> NaNOrZero() -{ - return T{}; + if constexpr (std::is_floating_point_v) + return std::numeric_limits::quiet_NaN(); + else + return {}; }