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