libstdc++: Make std::numeric_limits<__float128> more portable [PR104772]
commit6261d10521f9fdc2a43d54b4dc365025288aa8e9
authorJonathan Wakely <jwakely@redhat.com>
Mon, 5 Jun 2023 15:14:29 +0000 (5 16:14 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 6 Jun 2023 15:29:22 +0000 (6 16:29 +0100)
treef96ad957cbaf8b1d6b76704ca9f32b6751181df0
parent97a5e8a2a48d162744a5bd60a012ce6fca13cbbe
libstdc++: Make std::numeric_limits<__float128> more portable [PR104772]

This redefines std::numeric_limits<__float128> so that it works with
non-GCC compilers. The previous definition didn't work with Clang, due
to it not supporting __builtin_high_valq, __builtin_nanq, and
__builtin_nansq. It also didn't work in strict modes, due to using Q
literal suffixes.

The new definition uses the Q suffixes when supported, or calculates the
correct values using __float128 arithmetic from double values. Ideally
the values would be defined as hexadecimal-floating-point-literals, but
that won't work for C++14 and older.

The only member that can't be defined this way is signaling_NaN() which
still requires a built-in. If __builtin_nansq is not supported, try to
use __builtin_nansf128 (with a possibly-redundant bit_cast) and if that
isn't supported, return a quiet NaN and define has_signaling_NaN and
is_iec754 to be false.

libstdc++-v3/ChangeLog:

PR libstdc++/104772
* include/std/limits: (numeric_limits<__float128>): Define
for __STRICT_ANSI__ as well.
* testsuite/18_support/numeric_limits/128bit.cc: Remove
check for __STRICT_ANSI__.

Co-authored-by: Jakub Jelinek <jakub@redhat.com>
libstdc++-v3/include/std/limits
libstdc++-v3/testsuite/18_support/numeric_limits/128bit.cc