You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi Matt,
ccmath::abs() gives wrong result for FP-values std::numeric_limits<FP-Type>::min() in constexpr context.
test case:
using type = float;
constexpr type
a = std::numeric_limits<type>::min(),
b = boost::math::ccmath::abs(a);
std::cout << a << std::endl << b << std::endl;
1.17549e-38
nan
The Problem is:
template <typename T>
inline constexpr T abs_impl(T x) noexcept
{
return boost::math::ccmath::isnan(x) ? std::numeric_limits<T>::quiet_NaN() :
boost::math::ccmath::isinf(x) ? std::numeric_limits<T>::infinity() :
x == -0 ? T(0) :
x == (std::numeric_limits<T>::min)() ? std::numeric_limits<T>::quiet_NaN() :
x > 0 ? x : -x;
}
In the case of FP-types, only the sign-bit has to be deleted, since one cannot assume that quiet_NaN() and/or signaling_NaN() are always unsigned.
thx
Gero
The text was updated successfully, but these errors were encountered:
mborland
added a commit
to mborland/math
that referenced
this issue
Nov 11, 2022
From the ML:
The text was updated successfully, but these errors were encountered: