Boost logo

Boost :

From: Proton (matt_at_[hidden])
Date: 2022-11-11 03:46:45


> On Nov 10, 2022, at 11:47 AM, Gero Peterhoff via Boost <boost_at_[hidden]> wrote:
>
> 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
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
> <OpenPGP_signature.sig>

Gero,

I have opened your issue in Boost.Math (https://github.com/boostorg/math/issues/871). I should be able to get a fix in shortly.

Matt


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk