mirror of
https://sourceware.org/git/glibc.git
synced 2025-11-17 02:43:26 +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:
177
math/math.h
177
math/math.h
@@ -162,34 +162,201 @@ __BEGIN_DECLS
|
||||
to evaluate `float' expressions
|
||||
double_t floating-point type at least as wide as `double' used
|
||||
to evaluate `double' expressions
|
||||
|
||||
TS 18661-3 and C23 additionally define long_double_t and _FloatN_t.
|
||||
*/
|
||||
# if __GLIBC_FLT_EVAL_METHOD == 0 || __GLIBC_FLT_EVAL_METHOD == 16
|
||||
# if __GLIBC_FLT_EVAL_METHOD == 0
|
||||
typedef float float_t;
|
||||
typedef double double_t;
|
||||
# if __GLIBC_USE (IEC_60559_TYPES_EXT)
|
||||
typedef long double long_double_t;
|
||||
# if __HAVE_FLOAT16
|
||||
typedef float _Float16_t;
|
||||
# endif
|
||||
# if __HAVE_FLOAT32
|
||||
typedef _Float32 _Float32_t;
|
||||
# endif
|
||||
# if __HAVE_FLOAT64
|
||||
typedef _Float64 _Float64_t;
|
||||
# endif
|
||||
# if __HAVE_FLOAT128
|
||||
typedef _Float128 _Float128_t;
|
||||
# endif
|
||||
# endif
|
||||
# elif __GLIBC_FLT_EVAL_METHOD == 1
|
||||
typedef double float_t;
|
||||
typedef double double_t;
|
||||
# if __GLIBC_USE (IEC_60559_TYPES_EXT)
|
||||
typedef long double long_double_t;
|
||||
# if __HAVE_FLOAT16
|
||||
typedef double _Float16_t;
|
||||
# endif
|
||||
# if __HAVE_FLOAT32
|
||||
typedef double _Float32_t;
|
||||
# endif
|
||||
# if __HAVE_FLOAT64
|
||||
typedef _Float64 _Float64_t;
|
||||
# endif
|
||||
# if __HAVE_FLOAT128
|
||||
typedef _Float128 _Float128_t;
|
||||
# endif
|
||||
# endif
|
||||
# elif __GLIBC_FLT_EVAL_METHOD == 2
|
||||
typedef long double float_t;
|
||||
typedef long double double_t;
|
||||
# elif __GLIBC_FLT_EVAL_METHOD == 32
|
||||
typedef _Float32 float_t;
|
||||
# if __GLIBC_USE (IEC_60559_TYPES_EXT)
|
||||
typedef long double long_double_t;
|
||||
# if __HAVE_FLOAT16
|
||||
typedef long double _Float16_t;
|
||||
# endif
|
||||
# if __HAVE_FLOAT32
|
||||
typedef long double _Float32_t;
|
||||
# endif
|
||||
# if __HAVE_FLOAT64
|
||||
# ifdef __NO_LONG_DOUBLE_MATH
|
||||
typedef _Float64 _Float64_t;
|
||||
# else
|
||||
typedef long double _Float64_t;
|
||||
# endif
|
||||
# endif
|
||||
# if __HAVE_FLOAT128
|
||||
typedef _Float128 _Float128_t;
|
||||
# endif
|
||||
# endif
|
||||
# elif __GLIBC_FLT_EVAL_METHOD == 16
|
||||
typedef float float_t;
|
||||
typedef double double_t;
|
||||
# if __GLIBC_USE (IEC_60559_TYPES_EXT)
|
||||
typedef long double long_double_t;
|
||||
# if __HAVE_FLOAT16
|
||||
typedef _Float16 _Float16_t;
|
||||
# endif
|
||||
# if __HAVE_FLOAT32
|
||||
typedef _Float32 _Float32_t;
|
||||
# endif
|
||||
# if __HAVE_FLOAT64
|
||||
typedef _Float64 _Float64_t;
|
||||
# endif
|
||||
# if __HAVE_FLOAT128
|
||||
typedef _Float128 _Float128_t;
|
||||
# endif
|
||||
# endif
|
||||
# elif __GLIBC_FLT_EVAL_METHOD == 32
|
||||
typedef float float_t;
|
||||
typedef double double_t;
|
||||
# if __GLIBC_USE (IEC_60559_TYPES_EXT)
|
||||
typedef long double long_double_t;
|
||||
# if __HAVE_FLOAT16
|
||||
typedef _Float32 _Float16_t;
|
||||
# endif
|
||||
# if __HAVE_FLOAT32
|
||||
typedef _Float32 _Float32_t;
|
||||
# endif
|
||||
# if __HAVE_FLOAT64
|
||||
typedef _Float64 _Float64_t;
|
||||
# endif
|
||||
# if __HAVE_FLOAT128
|
||||
typedef _Float128 _Float128_t;
|
||||
# endif
|
||||
# endif
|
||||
# elif __GLIBC_FLT_EVAL_METHOD == 33
|
||||
typedef _Float32x float_t;
|
||||
typedef _Float32x double_t;
|
||||
typedef double double_t;
|
||||
# if __GLIBC_USE (IEC_60559_TYPES_EXT)
|
||||
typedef long double long_double_t;
|
||||
# if __HAVE_FLOAT16
|
||||
typedef _Float32x _Float16_t;
|
||||
# endif
|
||||
# if __HAVE_FLOAT32
|
||||
typedef _Float32x _Float32_t;
|
||||
# endif
|
||||
# if __HAVE_FLOAT64
|
||||
typedef _Float64 _Float64_t;
|
||||
# endif
|
||||
# if __HAVE_FLOAT128
|
||||
typedef _Float128 _Float128_t;
|
||||
# endif
|
||||
# endif
|
||||
# elif __GLIBC_FLT_EVAL_METHOD == 64
|
||||
typedef _Float64 float_t;
|
||||
typedef _Float64 double_t;
|
||||
typedef double double_t;
|
||||
# if __GLIBC_USE (IEC_60559_TYPES_EXT)
|
||||
typedef long double long_double_t;
|
||||
# if __HAVE_FLOAT16
|
||||
typedef _Float64 _Float16_t;
|
||||
# endif
|
||||
# if __HAVE_FLOAT32
|
||||
typedef _Float64 _Float32_t;
|
||||
# endif
|
||||
# if __HAVE_FLOAT64
|
||||
typedef _Float64 _Float64_t;
|
||||
# endif
|
||||
# if __HAVE_FLOAT128
|
||||
typedef _Float128 _Float128_t;
|
||||
# endif
|
||||
# endif
|
||||
# elif __GLIBC_FLT_EVAL_METHOD == 65
|
||||
typedef _Float64x float_t;
|
||||
typedef _Float64x double_t;
|
||||
# if __GLIBC_USE (IEC_60559_TYPES_EXT)
|
||||
typedef long double long_double_t;
|
||||
# if __HAVE_FLOAT16
|
||||
typedef _Float64x _Float16_t;
|
||||
# endif
|
||||
# if __HAVE_FLOAT32
|
||||
typedef _Float64x _Float32_t;
|
||||
# endif
|
||||
# if __HAVE_FLOAT64
|
||||
typedef _Float64x _Float64_t;
|
||||
# endif
|
||||
# if __HAVE_FLOAT128
|
||||
typedef _Float128 _Float128_t;
|
||||
# endif
|
||||
# endif
|
||||
# elif __GLIBC_FLT_EVAL_METHOD == 128
|
||||
typedef _Float128 float_t;
|
||||
typedef _Float128 double_t;
|
||||
# if __GLIBC_USE (IEC_60559_TYPES_EXT)
|
||||
# if __HAVE_FLOAT128_UNLIKE_LDBL && __LDBL_MANT_DIG__ != 106
|
||||
typedef _Float128 long_double_t;
|
||||
# else
|
||||
typedef long double long_double_t;
|
||||
# endif
|
||||
# if __HAVE_FLOAT16
|
||||
typedef _Float128 _Float16_t;
|
||||
# endif
|
||||
# if __HAVE_FLOAT32
|
||||
typedef _Float128 _Float32_t;
|
||||
# endif
|
||||
# if __HAVE_FLOAT64
|
||||
typedef _Float128 _Float64_t;
|
||||
# endif
|
||||
# if __HAVE_FLOAT128
|
||||
typedef _Float128 _Float128_t;
|
||||
# endif
|
||||
# endif
|
||||
# elif __GLIBC_FLT_EVAL_METHOD == 129
|
||||
typedef _Float128x float_t;
|
||||
typedef _Float128x double_t;
|
||||
# if __GLIBC_USE (IEC_60559_TYPES_EXT)
|
||||
# if __LDBL_MANT_DIG__ != 106
|
||||
typedef _Float128x long_double_t;
|
||||
# else
|
||||
typedef long double long_double_t;
|
||||
# endif
|
||||
# if __HAVE_FLOAT16
|
||||
typedef _Float128x _Float16_t;
|
||||
# endif
|
||||
# if __HAVE_FLOAT32
|
||||
typedef _Float128x _Float32_t;
|
||||
# endif
|
||||
# if __HAVE_FLOAT64
|
||||
typedef _Float128x _Float64_t;
|
||||
# endif
|
||||
# if __HAVE_FLOAT128
|
||||
typedef _Float128x _Float128_t;
|
||||
# endif
|
||||
# endif
|
||||
# else
|
||||
# error "Unknown __GLIBC_FLT_EVAL_METHOD"
|
||||
# endif
|
||||
|
||||
Reference in New Issue
Block a user