]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Fix std::abs(__float128) for -NaN and -0.0 [PR109758]
authorJonathan Wakely <jwakely@redhat.com>
Wed, 10 May 2023 11:20:58 +0000 (12:20 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 11 May 2023 11:16:21 +0000 (12:16 +0100)
commitaf595613acbd9863198ae69c7b1c9e856bca9e4f
tree5b50c79ef814a994cc3b13d59f709db1338b6381
parent0918360d709a32294913aef4392cec6c1dec1857
libstdc++: Fix std::abs(__float128) for -NaN and -0.0 [PR109758]

The current implementation of this non-standard overload of std::abs
incorrectly returns a negative value for negative NaNs and negative
zero, because x < 0 is false in both cases.

Use fabsl(long double) or fabsf128(_Float128) if those do the right
thing.  Otherwise, use __builtin_signbit(x) instead of x < 0 to detect
negative inputs. This assumes that __builtin_signbit handles __float128
correctly, but that seems to be true for all of GCC, clang and icc.

libstdc++-v3/ChangeLog:

PR libstdc++/109758
* include/bits/std_abs.h (abs(__float128)): Handle negative NaN
and negative zero correctly.
* testsuite/26_numerics/headers/cmath/109758.cc: New test.
libstdc++-v3/include/bits/std_abs.h
libstdc++-v3/testsuite/26_numerics/headers/cmath/109758.cc [new file with mode: 0644]