1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-11-18 14:01:04 +03:00

Add C23 long_double_t, _FloatN_t

C23 Annex H adds <math.h> typedefs long_double_t and _FloatN_t
(originally introduced in TS 18661-3), analogous to float_t and
double_t.  Add these typedefs to glibc.  (There are no _FloatNx_t
typedefs.)

C23 also slightly changes the rules for how such typedef names should
be defined, compared to the definition in TS 18661-3.  In both cases,
<TYPE>_t corresponds to the evaluation format for <TYPE>, as specified
by FLT_EVAL_METHOD (for which <math.h> uses glibc's internal
__GLIBC_FLT_EVAL_METHOD).  Specifically, each FLT_EVAL_METHOD value
corresponds to some type U (for example, 64 corresponds to U =
_Float64), and for types with exactly the same set of values as U, TS
18661-3 says expressions with those types are to be evaluated to the
range and precision of type U (so <TYPE>_t is defined to U), whereas
C23 only does that for types whose values are a strict subset of those
of type U (so <TYPE>_t is defined to <TYPE>).

As with other cases where semantics changed between TS 18661 and C23,
this patch only implements the newer version of the semantics
(including adjusting existing definitions of float_t and double_t as
needed).  The new semantics are contradictory between the main
standard and Annex H for the case of FLT_EVAL_METHOD == 2 and the
choice of double_t when double and long double have the same values
(the main standard says it's defined as long double in that case,
whereas Annex H would define it as double), which I've raised on the
WG14 reflector (but I think setting FLT_EVAL_METHOD == 2 when double
and long double have the same values is a fairly theoretical
combination of features); for now glibc follows the value in the main
standard in that case.

Note that I think all existing GCC targets supported by glibc only use
values -1, 0, 1, 2 or 16 for FLT_EVAL_METHOD (so most of the header
code is somewhat theoretical, though potentially relevant with other
compilers since the choice of FLT_EVAL_METHOD is only an API choice,
not an ABI one; it can vary with compiler options, and these typedefs
should not be used in ABIs).  The testcase (expanded to cover the new
typedefs) is really just repeating the same logic in a second place
(so all it really tests is that __GLIBC_FLT_EVAL_METHOD is consistent
with FLT_EVAL_METHOD).

Tested for x86_64 and x86, and with build-many-glibcs.py.
This commit is contained in:
Joseph Myers
2025-11-04 17:12:00 +00:00
parent 47975914fb
commit 26d11a0944
3 changed files with 363 additions and 10 deletions

View File

@@ -16,6 +16,7 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
#define __STDC_WANT_IEC_60559_TYPES_EXT__
#include <float.h>
#include <math.h>
@@ -23,33 +24,191 @@
/* Cannot test. */
typedef float_t my_float_t;
typedef double_t my_double_t;
#elif FLT_EVAL_METHOD == 0 || FLT_EVAL_METHOD == 16
typedef long_double_t my_long_double_t;
# if __HAVE_FLOAT16
typedef _Float16_t my_Float16_t;
# endif
# if __HAVE_FLOAT32
typedef _Float32_t my_Float32_t;
# endif
# if __HAVE_FLOAT64
typedef _Float64_t my_Float64_t;
# endif
# if __HAVE_FLOAT128
typedef _Float128_t my_Float128_t;
# endif
#elif FLT_EVAL_METHOD == 0
typedef float my_float_t;
typedef double my_double_t;
typedef long double my_long_double_t;
# if __HAVE_FLOAT16
typedef float my_Float16_t;
# endif
# if __HAVE_FLOAT32
typedef _Float32 my_Float32_t;
# endif
# if __HAVE_FLOAT64
typedef _Float64 my_Float64_t;
# endif
# if __HAVE_FLOAT128
typedef _Float128 my_Float128_t;
# endif
#elif FLT_EVAL_METHOD == 1
typedef double my_float_t;
typedef double my_double_t;
typedef long double my_long_double_t;
# if __HAVE_FLOAT16
typedef double my_Float16_t;
# endif
# if __HAVE_FLOAT32
typedef double my_Float32_t;
# endif
# if __HAVE_FLOAT64
typedef _Float64 my_Float64_t;
# endif
# if __HAVE_FLOAT128
typedef _Float128 my_Float128_t;
# endif
#elif FLT_EVAL_METHOD == 2
typedef long double my_float_t;
typedef long double my_double_t;
#elif FLT_EVAL_METHOD == 32
typedef _Float32 my_float_t;
typedef long double my_long_double_t;
# if __HAVE_FLOAT16
typedef long double my_Float16_t;
# endif
# if __HAVE_FLOAT32
typedef long double my_Float32_t;
# endif
# if __HAVE_FLOAT64
# ifdef __NO_LONG_DOUBLE_MATH
typedef _Float64 my_Float64_t;
# else
typedef long double my_Float64_t;
# endif
# endif
# if __HAVE_FLOAT128
typedef _Float128 my_Float128_t;
# endif
#elif FLT_EVAL_METHOD == 16
typedef float my_float_t;
typedef double my_double_t;
typedef long double my_long_double_t;
# if __HAVE_FLOAT16
typedef _Float16 my_Float16_t;
# endif
# if __HAVE_FLOAT32
typedef _Float32 my_Float32_t;
# endif
# if __HAVE_FLOAT64
typedef _Float64 my_Float64_t;
# endif
# if __HAVE_FLOAT128
typedef _Float128 my_Float128_t;
# endif
#elif FLT_EVAL_METHOD == 32
typedef float my_float_t;
typedef double my_double_t;
typedef long double my_long_double_t;
# if __HAVE_FLOAT16
typedef _Float32 my_Float16_t;
# endif
# if __HAVE_FLOAT32
typedef _Float32 my_Float32_t;
# endif
# if __HAVE_FLOAT64
typedef _Float64 my_Float64_t;
# endif
# if __HAVE_FLOAT128
typedef _Float128 my_Float128_t;
# endif
#elif FLT_EVAL_METHOD == 33
typedef _Float32x my_float_t;
typedef _Float32x my_double_t;
typedef double my_double_t;
typedef long double my_long_double_t;
# if __HAVE_FLOAT16
typedef _Float32x my_Float16_t;
# endif
# if __HAVE_FLOAT32
typedef _Float32x my_Float32_t;
# endif
# if __HAVE_FLOAT64
typedef _Float64 my_Float64_t;
# endif
# if __HAVE_FLOAT128
typedef _Float128 my_Float128_t;
# endif
#elif FLT_EVAL_METHOD == 64
typedef _Float64 my_float_t;
typedef _Float64 my_double_t;
typedef double my_double_t;
typedef long double my_long_double_t;
# if __HAVE_FLOAT16
typedef _Float64 my_Float16_t;
# endif
# if __HAVE_FLOAT32
typedef _Float64 my_Float32_t;
# endif
# if __HAVE_FLOAT64
typedef _Float64 my_Float64_t;
# endif
# if __HAVE_FLOAT128
typedef _Float128 my_Float128_t;
# endif
#elif FLT_EVAL_METHOD == 65
typedef _Float64x my_float_t;
typedef _Float64x my_double_t;
typedef long double my_long_double_t;
# if __HAVE_FLOAT16
typedef _Float64x my_Float16_t;
# endif
# if __HAVE_FLOAT32
typedef _Float64x my_Float32_t;
# endif
# if __HAVE_FLOAT64
typedef _Float64x my_Float64_t;
# endif
# if __HAVE_FLOAT128
typedef _Float128 my_Float128_t;
# endif
#elif FLT_EVAL_METHOD == 128
typedef _Float128 my_float_t;
typedef _Float128 my_double_t;
# if __HAVE_FLOAT128_UNLIKE_LDBL && __LDBL_MANT_DIG__ != 106
typedef _Float128 my_long_double_t;
# else
typedef long double my_long_double_t;
# endif
# if __HAVE_FLOAT16
typedef _Float128 my_Float16_t;
# endif
# if __HAVE_FLOAT32
typedef _Float128 my_Float32_t;
# endif
# if __HAVE_FLOAT64
typedef _Float128 my_Float64_t;
# endif
# if __HAVE_FLOAT128
typedef _Float128 my_Float128_t;
# endif
#elif FLT_EVAL_METHOD == 129
typedef _Float128x my_float_t;
typedef _Float128x my_double_t;
# if __LDBL_MANT_DIG__ != 106
typedef _Float128x my_long_double_t;
# else
typedef long double my_long_double_t;
# endif
# if __HAVE_FLOAT16
typedef _Float128x my_Float16_t;
# endif
# if __HAVE_FLOAT32
typedef _Float128x my_Float32_t;
# endif
# if __HAVE_FLOAT64
typedef _Float128x my_Float64_t;
# endif
# if __HAVE_FLOAT128
typedef _Float128x my_Float128_t;
# endif
#else
# error "Unknown FLT_EVAL_METHOD"
#endif
@@ -60,6 +219,29 @@ extern my_float_t test_float_t;
extern double_t test_double_t;
extern my_double_t test_double_t;
extern long_double_t test_long_double_t;
extern my_long_double_t test_long_double_t;
#if __HAVE_FLOAT16
extern _Float16_t test_Float16_t;
extern my_Float16_t test_Float16_t;
#endif
#if __HAVE_FLOAT32
extern _Float32_t test_Float32_t;
extern my_Float32_t test_Float32_t;
#endif
#if __HAVE_FLOAT64
extern _Float64_t test_Float64_t;
extern my_Float64_t test_Float64_t;
#endif
#if __HAVE_FLOAT128
extern _Float128_t test_Float128_t;
extern my_Float128_t test_Float128_t;
#endif
/* This is a compilation test. */
#define TEST_FUNCTION 0
#include "../test-skeleton.c"