Skip to content

Commit a7704d2

Browse files
committed
Don't change sign of nans
1 parent 51113cc commit a7704d2

File tree

1 file changed

+8
-1
lines changed
  • include/boost/decimal/detail/cmath

1 file changed

+8
-1
lines changed

include/boost/decimal/detail/cmath/abs.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@ BOOST_DECIMAL_EXPORT template <typename T>
2222
constexpr auto abs BOOST_DECIMAL_PREVENT_MACRO_SUBSTITUTION (const T rhs) noexcept
2323
BOOST_DECIMAL_REQUIRES(detail::is_decimal_floating_point_v, T)
2424
{
25-
return signbit(rhs) ? -rhs : rhs;
25+
if (BOOST_DECIMAL_LIKELY(!isnan(rhs)))
26+
{
27+
return signbit(rhs) ? -rhs : rhs;
28+
}
29+
else
30+
{
31+
return issignaling(rhs) ? nan_conversion(rhs) : rhs;
32+
}
2633
}
2734

2835
} // namespace decimal

0 commit comments

Comments
 (0)