From 178312d414b2250d1ffbb7fc12becd343d9abd18 Mon Sep 17 00:00:00 2001 From: serge-sans-paille Date: Mon, 12 May 2025 08:32:23 +0200 Subject: [PATCH 1/2] Force XSIMD_NO_INFINITIES XSIMD_NO_NANS and XSIMD_NO_DENORMALS under __FAST_MATH__ --- include/xsimd/xsimd.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/xsimd/xsimd.hpp b/include/xsimd/xsimd.hpp index b5548e7ac..1ae9f5867 100644 --- a/include/xsimd/xsimd.hpp +++ b/include/xsimd/xsimd.hpp @@ -12,6 +12,12 @@ #ifndef XSIMD_HPP #define XSIMD_HPP +#if defined(__FAST_MATH__) +#define XSIMD_NO_DENORMALS +#define XSIMD_NO_INFINITIES +#define XSIMD_NO_NANS +#endif + #if defined(__has_cpp_attribute) // if this check passes, then the compiler supports feature test macros #if __has_cpp_attribute(nodiscard) >= 201603L From 03d48b57d7064e43e6ec77bca76459abcf494b25 Mon Sep 17 00:00:00 2001 From: serge-sans-paille Date: Mon, 12 May 2025 08:32:57 +0200 Subject: [PATCH 2/2] Fix log10 implementation under -ffast-math Fix #1116 --- include/xsimd/arch/common/xsimd_common_math.hpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/include/xsimd/arch/common/xsimd_common_math.hpp b/include/xsimd/arch/common/xsimd_common_math.hpp index 71dc75787..5962549c7 100644 --- a/include/xsimd/arch/common/xsimd_common_math.hpp +++ b/include/xsimd/arch/common/xsimd_common_math.hpp @@ -1694,9 +1694,15 @@ namespace xsimd #ifndef XSIMD_NO_INFINITIES batch_type zz = select(isnez, select(self == constants::infinity(), constants::infinity(), r), constants::minusinfinity()); #else - batch_type zz = select(isnez, r, constants::minusinfinity()); + assert(all(isnez) && "Calling log10 on a batch with zero value while XSIMD_NO_INFINITIES is active"); + batch_type zz = r; #endif +#ifndef XSIMD_NO_NANS return select(!(self >= batch_type(0.)), constants::nan(), zz); +#else + assert(all(self >= batch_type(0.)) && "Calling log10 on a batch with negative value while XSIMD_NO_NANS is active"); + return zz; +#endif } template @@ -2475,7 +2481,7 @@ namespace xsimd { using batch_type = batch; auto nan_result = (self < batch_type(0.) && is_flint(self)); -#ifndef XSIMD_NO_INVALIDS +#ifndef XSIMD_NO_NANS nan_result = isnan(self) || nan_result; #endif batch_type q = abs(self);