aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/std/limits
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2022-10-18 11:37:13 +0200
committerJakub Jelinek <jakub@redhat.com>2022-10-18 11:37:13 +0200
commita23225fb4f764dfc3e3e729c7d7238f03f282aaa (patch)
treebaec5306bacfffa31842bd6d26b5afa8c45114f5 /libstdc++-v3/include/std/limits
parent4dda30e9910c4f04a6258b053401249e213f29be (diff)
downloadgcc-a23225fb4f764dfc3e3e729c7d7238f03f282aaa.zip
gcc-a23225fb4f764dfc3e3e729c7d7238f03f282aaa.tar.gz
gcc-a23225fb4f764dfc3e3e729c7d7238f03f282aaa.tar.bz2
libstdc++: Partial library support for std::float{16,32,64,128}_t and std::bfloat16_t
The following patch is partial support for std::float{16,32,64,128}_t and std::bfloat16_t in libstdc++. https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p1467r9.html says that <ostream>, <istream>, <charconv> and <complex> need changes toom, but that isn't implemented so far. In <cmath> the only thing missing I'm aware of is std::nextafter std::float16_t and std::bfloat16_t overloads (I think we probably need to implement that out of line somewhere, or inline? - might need inline asm barriers) and std::nexttoward overloads (those are intentional, you said there is a LWG issue about that). Also, this patch has the glibc 2.26+ std::float128_t support for platforms where long double isn't IEEE quad format temporarily disabled because it depends on https://gcc.gnu.org/pipermail/gcc-patches/2022-October/603665.html changes which aren't in yet. The patch also doesn't include any testcases to cover the <type_traits> changes, it isn't clear to me where to put that. 2022-10-18 Jakub Jelinek <jakub@redhat.com> PR c++/106652 * include/std/stdfloat: New file. * include/std/numbers (__glibcxx_numbers): Define and use it for __float128 explicit instantiations as well as _Float{16,32,64,128} and __gnu_cxx::__bfloat16_t. * include/std/atomic (atomic<_Float16>, atomic<_Float32>, atomic<_Float64>, atomic<_Float128>, atomic<__gnu_cxx::__bfloat16_t>): New explicit instantiations. * include/std/type_traits (__is_floating_point_helper<_Float16>, __is_floating_point_helper<_Float32>, __is_floating_point_helper<_Float64>, __is_floating_point_helper<_Float128>, __is_floating_point_helper<__gnu_cxx::__bfloat16_t>): Likewise. * include/std/limits (__glibcxx_concat3_, __glibcxx_concat3, __glibcxx_float_n): Define. (numeric_limits<_Float16>, numeric_limits<_Float32>, numeric_limits<_Float64>, numeric_limits<_Float128>, numeric_limits<__gnu_cxx::__bfloat16_t>): New explicit instantiations. * include/bits/std_abs.h (abs): New overloads for _Float{16,32,64,128} and __gnu_cxx::__bfloat16_t. * include/bits/c++config (_GLIBCXX_LDOUBLE_IS_IEEE_BINARY128): Define if long double is IEEE quad. (__gnu_cxx::__bfloat16_t): New using. * include/c_global/cmath (acos, asin, atan, atan2, ceil, cos, cosh, exp, fabs, floor, fmod, frexp, ldexp, log, log10, modf, pow, sin, sinh, sqrt, tan, tanh, fpclassify, isfinite, isinf, isnan, isnormal, signbit, isgreater, isgreaterequal, isless, islessequal, islessgreater, isunordered, acosh, asinh, atanh, cbrt, copysign, erf, erfc, exp2, expm1, fdim, fma, fmax, fmin, hypot, ilogb, lgamma, llrint, llround, log1p, log2, logb, lrint, lround, nearbyint, nextafter, remainder, rint, round, scalbln, scalbn, tgamma, trunc, lerp): New overloads with _Float{16,32,64,128} or __gnu_cxx::__bfloat16_t types. * config/os/gnu-linux/os_defines.h (_GLIBCXX_HAVE_FLOAT128_MATH): Prepare for definition if glibc 2.26 and later implements *f128 APIs but comment out the actual definition for now. * include/ext/type_traits.h (__promote<_Float16>, __promote<_Float32>, __promote<_Float64>, __promote<_Float128>, __promote<__gnu_cxx::__bfloat16_t>): New specializations. * include/Makefile.am (std_headers): Add stdfloat. * include/Makefile.in: Regenerated. * include/precompiled/stdc++.h: Include stdfloat. * testsuite/18_support/headers/stdfloat/types_std.cc: New test. * testsuite/18_support/headers/limits/synopsis_cxx23.cc: New test. * testsuite/26_numerics/headers/cmath/c99_classification_macros_c++23.cc: New test. * testsuite/26_numerics/headers/cmath/functions_std_c++23.cc: New test. * testsuite/26_numerics/numbers/4.cc: New test. * testsuite/29_atomics/atomic_float/requirements_cxx23.cc: New test.
Diffstat (limited to 'libstdc++-v3/include/std/limits')
-rw-r--r--libstdc++-v3/include/std/limits184
1 files changed, 184 insertions, 0 deletions
diff --git a/libstdc++-v3/include/std/limits b/libstdc++-v3/include/std/limits
index a60611b..61b6c3b 100644
--- a/libstdc++-v3/include/std/limits
+++ b/libstdc++-v3/include/std/limits
@@ -1890,6 +1890,190 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#undef __glibcxx_long_double_traps
#undef __glibcxx_long_double_tinyness_before
+#if __cplusplus > 202202L
+
+#define __glibcxx_concat3_(P,M,S) P ## M ## S
+#define __glibcxx_concat3(P,M,S) __glibcxx_concat3_ (P,M,S)
+
+#define __glibcxx_float_n(BITSIZE) \
+ __extension__ \
+ template<> \
+ struct numeric_limits<_Float##BITSIZE> \
+ { \
+ static constexpr bool is_specialized = true; \
+ \
+ static constexpr _Float##BITSIZE \
+ min() noexcept \
+ { return __glibcxx_concat3 (__FLT, BITSIZE, _MIN__); } \
+ \
+ static constexpr _Float##BITSIZE \
+ max() noexcept \
+ { return __glibcxx_concat3 (__FLT, BITSIZE, _MAX__); } \
+ \
+ static constexpr _Float##BITSIZE \
+ lowest() noexcept \
+ { return -__glibcxx_concat3 (__FLT, BITSIZE, _MAX__); } \
+ \
+ static constexpr int digits \
+ = __glibcxx_concat3 (__FLT, BITSIZE, _MANT_DIG__); \
+ static constexpr int digits10 \
+ = __glibcxx_concat3 (__FLT, BITSIZE, _DIG__); \
+ static constexpr int max_digits10 \
+ = __glibcxx_max_digits10 (__glibcxx_concat3 (__FLT, BITSIZE, \
+ _MANT_DIG__)); \
+ static constexpr bool is_signed = true; \
+ static constexpr bool is_integer = false; \
+ static constexpr bool is_exact = false; \
+ static constexpr int radix \
+ = __glibcxx_concat3 (__FLT, BITSIZE, _RADIX__); \
+ \
+ static constexpr _Float##BITSIZE \
+ epsilon() noexcept \
+ { return __glibcxx_concat3 (__FLT, BITSIZE, _EPSILON__); } \
+ \
+ static constexpr _Float##BITSIZE \
+ round_error() noexcept { return 0.5F##BITSIZE; } \
+ \
+ static constexpr int min_exponent \
+ = __glibcxx_concat3 (__FLT, BITSIZE, _MIN_EXP__); \
+ static constexpr int min_exponent10 \
+ = __glibcxx_concat3 (__FLT, BITSIZE, _MIN_10_EXP__); \
+ static constexpr int max_exponent \
+ = __glibcxx_concat3 (__FLT, BITSIZE, _MAX_EXP__); \
+ static constexpr int max_exponent10 \
+ = __glibcxx_concat3 (__FLT, BITSIZE, _MAX_10_EXP__); \
+ \
+ static constexpr bool has_infinity \
+ = __glibcxx_concat3 (__FLT, BITSIZE, _HAS_INFINITY__); \
+ static constexpr bool has_quiet_NaN \
+ = __glibcxx_concat3 (__FLT, BITSIZE, _HAS_QUIET_NAN__); \
+ static constexpr bool has_signaling_NaN \
+ = has_quiet_NaN; \
+ static constexpr float_denorm_style has_denorm \
+ = bool(__glibcxx_concat3 (__FLT, BITSIZE, _HAS_DENORM__)) \
+ ? denorm_present : denorm_absent; \
+ static constexpr bool has_denorm_loss = false; \
+ \
+ static constexpr _Float##BITSIZE \
+ infinity() noexcept \
+ { return __builtin_huge_valf##BITSIZE(); } \
+ \
+ static constexpr _Float##BITSIZE \
+ quiet_NaN() noexcept \
+ { return __builtin_nanf##BITSIZE(""); } \
+ \
+ static constexpr _Float##BITSIZE \
+ signaling_NaN() noexcept \
+ { return __builtin_nansf##BITSIZE(""); } \
+ \
+ static constexpr _Float##BITSIZE \
+ denorm_min() noexcept \
+ { return __glibcxx_concat3 (__FLT, BITSIZE, _DENORM_MIN__); } \
+ \
+ static constexpr bool is_iec559 \
+ = has_infinity && has_quiet_NaN && has_denorm == denorm_present;\
+ static constexpr bool is_bounded = true; \
+ static constexpr bool is_modulo = false; \
+ \
+ static constexpr bool traps = false; \
+ static constexpr bool tinyness_before = false; \
+ static constexpr float_round_style round_style \
+ = round_to_nearest; \
+ }; \
+
+#ifdef __STDCPP_FLOAT16_T__
+__glibcxx_float_n(16)
+#endif
+#ifdef __STDCPP_FLOAT32_T__
+__glibcxx_float_n(32)
+#endif
+#ifdef __STDCPP_FLOAT64_T__
+__glibcxx_float_n(64)
+#endif
+#ifdef __STDCPP_FLOAT128_T__
+__glibcxx_float_n(128)
+#endif
+#undef __glibcxx_float_n
+#undef __glibcxx_concat3
+#undef __glibcxx_concat3_
+
+#ifdef __STDCPP_BFLOAT16_T__
+ __extension__
+ template<>
+ struct numeric_limits<__gnu_cxx::__bfloat16_t>
+ {
+ static constexpr bool is_specialized = true;
+
+ static constexpr __gnu_cxx::__bfloat16_t
+ min() noexcept
+ { return __BFLT16_MIN__; }
+
+ static constexpr __gnu_cxx::__bfloat16_t
+ max() noexcept
+ { return __BFLT16_MAX__; }
+
+ static constexpr __gnu_cxx::__bfloat16_t
+ lowest() noexcept
+ { return -__BFLT16_MAX__; }
+
+ static constexpr int digits = __BFLT16_MANT_DIG__;
+ static constexpr int digits10 = __BFLT16_DIG__;
+ static constexpr int max_digits10
+ = __glibcxx_max_digits10 (__BFLT16_MANT_DIG__);
+ static constexpr bool is_signed = true;
+ static constexpr bool is_integer = false;
+ static constexpr bool is_exact = false;
+ static constexpr int radix = __BFLT16_RADIX__;
+
+ static constexpr __gnu_cxx::__bfloat16_t
+ epsilon() noexcept
+ { return __BFLT16_EPSILON__; }
+
+ static constexpr __gnu_cxx::__bfloat16_t
+ round_error() noexcept { return 0.5BF16; }
+
+ static constexpr int min_exponent = __BFLT16_MIN_EXP__;
+ static constexpr int min_exponent10 = __BFLT16_MIN_10_EXP__;
+ static constexpr int max_exponent = __BFLT16_MAX_EXP__;
+ static constexpr int max_exponent10 = __BFLT16_MAX_10_EXP__;
+
+ static constexpr bool has_infinity = __BFLT16_HAS_INFINITY__;
+ static constexpr bool has_quiet_NaN = __BFLT16_HAS_QUIET_NAN__;
+ static constexpr bool has_signaling_NaN = has_quiet_NaN;
+ static constexpr float_denorm_style has_denorm
+ = bool(__BFLT16_HAS_DENORM__)
+ ? denorm_present : denorm_absent;
+ static constexpr bool has_denorm_loss = false;
+
+ static constexpr __gnu_cxx::__bfloat16_t
+ infinity() noexcept
+ { return __gnu_cxx::__bfloat16_t(__builtin_huge_valf()); }
+
+ static constexpr __gnu_cxx::__bfloat16_t
+ quiet_NaN() noexcept
+ { return __gnu_cxx::__bfloat16_t(__builtin_nanf("")); }
+
+ static constexpr __gnu_cxx::__bfloat16_t
+ signaling_NaN() noexcept
+ { return __builtin_nansf16b(""); }
+
+ static constexpr __gnu_cxx::__bfloat16_t
+ denorm_min() noexcept
+ { return __BFLT16_DENORM_MIN__; }
+
+ static constexpr bool is_iec559
+ = has_infinity && has_quiet_NaN && has_denorm == denorm_present;
+ static constexpr bool is_bounded = true;
+ static constexpr bool is_modulo = false;
+
+ static constexpr bool traps = false;
+ static constexpr bool tinyness_before = false;
+ static constexpr float_round_style round_style = round_to_nearest;
+ };
+#endif
+
+#endif
+
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace