mirror of
https://sourceware.org/git/glibc.git
synced 2025-11-17 02:43:26 +03:00
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.
248 lines
5.8 KiB
C
248 lines
5.8 KiB
C
/* Test evaluation method typedefs match FLT_EVAL_METHOD.
|
|
Copyright (C) 2016-2025 Free Software Foundation, Inc.
|
|
This file is part of the GNU C Library.
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
The GNU C 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
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
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>
|
|
|
|
#if FLT_EVAL_METHOD == -1
|
|
/* Cannot test. */
|
|
typedef float_t my_float_t;
|
|
typedef double_t my_double_t;
|
|
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;
|
|
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 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 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
|
|
|
|
extern float_t test_float_t;
|
|
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"
|