gcc/libstdc++-v3/testsuite/26_numerics/numbers/4.cc

122 lines
5.6 KiB
C++
Raw Permalink Normal View History

2025-01-02 11:59:57 +01:00
// Copyright (C) 2022-2025 Free Software Foundation, Inc.
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.
2022-10-18 11:37:13 +02:00
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-do compile { target c++23 } }
#include <numbers>
#include <stdfloat>
#if defined(__STDCPP_FLOAT16_T__)
void
test01()
{
const std::float16_t* d1 = &std::numbers::e_v<std::float16_t>;
const std::float16_t* d2 = &std::numbers::log2e_v<std::float16_t>;
const std::float16_t* d3 = &std::numbers::log10e_v<std::float16_t>;
const std::float16_t* d4 = &std::numbers::pi_v<std::float16_t>;
const std::float16_t* d5 = &std::numbers::inv_pi_v<std::float16_t>;
const std::float16_t* d6 = &std::numbers::inv_sqrtpi_v<std::float16_t>;
const std::float16_t* d7 = &std::numbers::ln2_v<std::float16_t>;
const std::float16_t* d8 = &std::numbers::ln10_v<std::float16_t>;
const std::float16_t* d9 = &std::numbers::sqrt2_v<std::float16_t>;
const std::float16_t* d10 = &std::numbers::sqrt3_v<std::float16_t>;
const std::float16_t* d11 = &std::numbers::inv_sqrt3_v<std::float16_t>;
const std::float16_t* d12 = &std::numbers::egamma_v<std::float16_t>;
const std::float16_t* d13 = &std::numbers::phi_v<std::float16_t>;
}
#endif
#if defined(__STDCPP_FLOAT32_T__)
void
test02()
{
const std::float32_t* d1 = &std::numbers::e_v<std::float32_t>;
const std::float32_t* d2 = &std::numbers::log2e_v<std::float32_t>;
const std::float32_t* d3 = &std::numbers::log10e_v<std::float32_t>;
const std::float32_t* d4 = &std::numbers::pi_v<std::float32_t>;
const std::float32_t* d5 = &std::numbers::inv_pi_v<std::float32_t>;
const std::float32_t* d6 = &std::numbers::inv_sqrtpi_v<std::float32_t>;
const std::float32_t* d7 = &std::numbers::ln2_v<std::float32_t>;
const std::float32_t* d8 = &std::numbers::ln10_v<std::float32_t>;
const std::float32_t* d9 = &std::numbers::sqrt2_v<std::float32_t>;
const std::float32_t* d10 = &std::numbers::sqrt3_v<std::float32_t>;
const std::float32_t* d11 = &std::numbers::inv_sqrt3_v<std::float32_t>;
const std::float32_t* d12 = &std::numbers::egamma_v<std::float32_t>;
const std::float32_t* d13 = &std::numbers::phi_v<std::float32_t>;
}
#endif
#if defined(__STDCPP_FLOAT64_T__)
void
test03()
{
const std::float64_t* d1 = &std::numbers::e_v<std::float64_t>;
const std::float64_t* d2 = &std::numbers::log2e_v<std::float64_t>;
const std::float64_t* d3 = &std::numbers::log10e_v<std::float64_t>;
const std::float64_t* d4 = &std::numbers::pi_v<std::float64_t>;
const std::float64_t* d5 = &std::numbers::inv_pi_v<std::float64_t>;
const std::float64_t* d6 = &std::numbers::inv_sqrtpi_v<std::float64_t>;
const std::float64_t* d7 = &std::numbers::ln2_v<std::float64_t>;
const std::float64_t* d8 = &std::numbers::ln10_v<std::float64_t>;
const std::float64_t* d9 = &std::numbers::sqrt2_v<std::float64_t>;
const std::float64_t* d10 = &std::numbers::sqrt3_v<std::float64_t>;
const std::float64_t* d11 = &std::numbers::inv_sqrt3_v<std::float64_t>;
const std::float64_t* d12 = &std::numbers::egamma_v<std::float64_t>;
const std::float64_t* d13 = &std::numbers::phi_v<std::float64_t>;
}
#endif
#if defined(__STDCPP_FLOAT128_T__)
void
test04()
{
const std::float128_t* d1 = &std::numbers::e_v<std::float128_t>;
const std::float128_t* d2 = &std::numbers::log2e_v<std::float128_t>;
const std::float128_t* d3 = &std::numbers::log10e_v<std::float128_t>;
const std::float128_t* d4 = &std::numbers::pi_v<std::float128_t>;
const std::float128_t* d5 = &std::numbers::inv_pi_v<std::float128_t>;
const std::float128_t* d6 = &std::numbers::inv_sqrtpi_v<std::float128_t>;
const std::float128_t* d7 = &std::numbers::ln2_v<std::float128_t>;
const std::float128_t* d8 = &std::numbers::ln10_v<std::float128_t>;
const std::float128_t* d9 = &std::numbers::sqrt2_v<std::float128_t>;
const std::float128_t* d10 = &std::numbers::sqrt3_v<std::float128_t>;
const std::float128_t* d11 = &std::numbers::inv_sqrt3_v<std::float128_t>;
const std::float128_t* d12 = &std::numbers::egamma_v<std::float128_t>;
const std::float128_t* d13 = &std::numbers::phi_v<std::float128_t>;
}
#endif
#if defined(__STDCPP_BFLOAT16_T__)
void
test05()
{
const std::bfloat16_t* d1 = &std::numbers::e_v<std::bfloat16_t>;
const std::bfloat16_t* d2 = &std::numbers::log2e_v<std::bfloat16_t>;
const std::bfloat16_t* d3 = &std::numbers::log10e_v<std::bfloat16_t>;
const std::bfloat16_t* d4 = &std::numbers::pi_v<std::bfloat16_t>;
const std::bfloat16_t* d5 = &std::numbers::inv_pi_v<std::bfloat16_t>;
const std::bfloat16_t* d6 = &std::numbers::inv_sqrtpi_v<std::bfloat16_t>;
const std::bfloat16_t* d7 = &std::numbers::ln2_v<std::bfloat16_t>;
const std::bfloat16_t* d8 = &std::numbers::ln10_v<std::bfloat16_t>;
const std::bfloat16_t* d9 = &std::numbers::sqrt2_v<std::bfloat16_t>;
const std::bfloat16_t* d10 = &std::numbers::sqrt3_v<std::bfloat16_t>;
const std::bfloat16_t* d11 = &std::numbers::inv_sqrt3_v<std::bfloat16_t>;
const std::bfloat16_t* d12 = &std::numbers::egamma_v<std::bfloat16_t>;
const std::bfloat16_t* d13 = &std::numbers::phi_v<std::bfloat16_t>;
}
#endif