From a7704d28bd9be57ccc4824bdd3fa70c1c2a8522a Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Fri, 21 Nov 2025 14:16:14 +0100 Subject: [PATCH] Don't change sign of nans --- include/boost/decimal/detail/cmath/abs.hpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/boost/decimal/detail/cmath/abs.hpp b/include/boost/decimal/detail/cmath/abs.hpp index b7da73126..e0fca14c6 100644 --- a/include/boost/decimal/detail/cmath/abs.hpp +++ b/include/boost/decimal/detail/cmath/abs.hpp @@ -22,7 +22,14 @@ BOOST_DECIMAL_EXPORT template constexpr auto abs BOOST_DECIMAL_PREVENT_MACRO_SUBSTITUTION (const T rhs) noexcept BOOST_DECIMAL_REQUIRES(detail::is_decimal_floating_point_v, T) { - return signbit(rhs) ? -rhs : rhs; + if (BOOST_DECIMAL_LIKELY(!isnan(rhs))) + { + return signbit(rhs) ? -rhs : rhs; + } + else + { + return issignaling(rhs) ? nan_conversion(rhs) : rhs; + } } } // namespace decimal