From 3cfe746fc5255f8dd1674bf4a8873b7b8e178c89 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Tue, 17 Nov 2020 00:25:12 +0000 Subject: float.h: C2x NaN and Inf macros C2x adds macros for NaNs and infinities to , some of them previously in (and some still in as well in C2x as an obsolescent feature). Add these macros to GCC's implementation. This omits the macros for DFP signaling NaNs, leaving those to be added in a separate patch. However, it includes the _FloatN / _FloatNx macros (conditional on __STDC_WANT_IEC_60559_TYPES_EXT__) in the current draft version of the integration of TS 18661-3 into C2x as an Annex. As GCC allows duplicate macro definitions with different expansions in system headers, it should be OK if defines INFINITY or NAN with a slightly different expansion (e.g. different choice of whether there is whitespace between tokens); tests are added including and in either order. Because uses #undef on all macros before defining them, even with -Wsystem-headers there could only ever be issues when is included after . Bootstrapped with no regressions on x86_64-pc-linux-gnu. gcc/ 2020-11-17 Joseph Myers * ginclude/float.h (INFINITY, NAN, FLT_SNAN, DBL_SNAN, LDBL_SNAN) (FLT16_SNAN, FLT32_SNAN, FLT64_SNAN, FLT128_SNAN, FLT32X_SNAN) (FLT64X_SNAN, FLT128X_SNAN, DEC_INFINITY, DEC_NAN): New C2x macros. * doc/sourcebuild.texi (Effective-Target Keywords): Document inff. gcc/testsuite/ 2020-11-17 Joseph Myers * lib/target-supports.exp (check_effective_target_inff): New. * gcc.dg/c11-float-4.c, gcc.dg/c11-float-5.c, gcc.dg/c11-float-dfp-2.c, gcc.dg/c2x-float-2.c, gcc.dg/c2x-float-3.c, gcc.dg/c2x-float-4.c, gcc.dg/c2x-float-5.c, gcc.dg/c2x-float-6.c, gcc.dg/c2x-float-7.c, gcc.dg/c2x-float-8.c, gcc.dg/c2x-float-9.c, gcc.dg/c2x-float-no-dfp-3.c, gcc.dg/c2x-float-no-dfp-4.c, gcc.dg/dfp/c2x-float-dfp-4.c, gcc.dg/dfp/c2x-float-dfp-5.c, gcc.dg/dfp/c2x-float-dfp-6.c, gcc.dg/torture/float128-nan-floath.c, gcc.dg/torture/float128x-nan-floath.c, gcc.dg/torture/float16-nan-floath.c, gcc.dg/torture/float32-nan-floath.c, gcc.dg/torture/float32x-nan-floath.c, gcc.dg/torture/float64-nan-floath.c, gcc.dg/torture/float64x-nan-floath.c, gcc.dg/torture/floatn-nan-floath.h: New tests. --- gcc/ginclude/float.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'gcc/ginclude') diff --git a/gcc/ginclude/float.h b/gcc/ginclude/float.h index 9c4b038..7744699 100644 --- a/gcc/ginclude/float.h +++ b/gcc/ginclude/float.h @@ -248,6 +248,32 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #define DBL_NORM_MAX __DBL_NORM_MAX__ #define LDBL_NORM_MAX __LDBL_NORM_MAX__ +/* Infinity in type float, or overflow if infinity not supported. */ +#undef INFINITY +#define INFINITY (__builtin_inff ()) + +/* Quiet NaN, if supported for float. */ +#if __FLT_HAS_QUIET_NAN__ +#undef NAN +#define NAN (__builtin_nanf ("")) +#endif + +/* Signaling NaN, if supported for each type. All formats supported + by GCC support either both quiet and signaling NaNs, or neither + kind of NaN. */ +#if __FLT_HAS_QUIET_NAN__ +#undef FLT_SNAN +#define FLT_SNAN (__builtin_nansf ("")) +#endif +#if __DBL_HAS_QUIET_NAN__ +#undef DBL_SNAN +#define DBL_SNAN (__builtin_nans ("")) +#endif +#if __LDBL_HAS_QUIET_NAN__ +#undef LDBL_SNAN +#define LDBL_SNAN (__builtin_nansl ("")) +#endif + #endif /* C2X */ #ifdef __STDC_WANT_IEC_60559_BFP_EXT__ @@ -284,6 +310,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #define FLT16_DECIMAL_DIG __FLT16_DECIMAL_DIG__ #undef FLT16_TRUE_MIN #define FLT16_TRUE_MIN __FLT16_DENORM_MIN__ +#if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L +#undef FLT16_SNAN +#define FLT16_SNAN (__builtin_nansf16 ("")) +#endif /* C2X */ #endif /* __FLT16_MANT_DIG__. */ #ifdef __FLT32_MANT_DIG__ @@ -309,6 +339,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #define FLT32_DECIMAL_DIG __FLT32_DECIMAL_DIG__ #undef FLT32_TRUE_MIN #define FLT32_TRUE_MIN __FLT32_DENORM_MIN__ +#if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L +#undef FLT32_SNAN +#define FLT32_SNAN (__builtin_nansf32 ("")) +#endif /* C2X */ #endif /* __FLT32_MANT_DIG__. */ #ifdef __FLT64_MANT_DIG__ @@ -334,6 +368,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #define FLT64_DECIMAL_DIG __FLT64_DECIMAL_DIG__ #undef FLT64_TRUE_MIN #define FLT64_TRUE_MIN __FLT64_DENORM_MIN__ +#if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L +#undef FLT64_SNAN +#define FLT64_SNAN (__builtin_nansf64 ("")) +#endif /* C2X */ #endif /* __FLT64_MANT_DIG__. */ #ifdef __FLT128_MANT_DIG__ @@ -359,6 +397,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #define FLT128_DECIMAL_DIG __FLT128_DECIMAL_DIG__ #undef FLT128_TRUE_MIN #define FLT128_TRUE_MIN __FLT128_DENORM_MIN__ +#if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L +#undef FLT128_SNAN +#define FLT128_SNAN (__builtin_nansf128 ("")) +#endif /* C2X */ #endif /* __FLT128_MANT_DIG__. */ #ifdef __FLT32X_MANT_DIG__ @@ -384,6 +426,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #define FLT32X_DECIMAL_DIG __FLT32X_DECIMAL_DIG__ #undef FLT32X_TRUE_MIN #define FLT32X_TRUE_MIN __FLT32X_DENORM_MIN__ +#if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L +#undef FLT32X_SNAN +#define FLT32X_SNAN (__builtin_nansf32x ("")) +#endif /* C2X */ #endif /* __FLT32X_MANT_DIG__. */ #ifdef __FLT64X_MANT_DIG__ @@ -409,6 +455,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #define FLT64X_DECIMAL_DIG __FLT64X_DECIMAL_DIG__ #undef FLT64X_TRUE_MIN #define FLT64X_TRUE_MIN __FLT64X_DENORM_MIN__ +#if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L +#undef FLT64X_SNAN +#define FLT64X_SNAN (__builtin_nansf64x ("")) +#endif /* C2X */ #endif /* __FLT64X_MANT_DIG__. */ #ifdef __FLT128X_MANT_DIG__ @@ -434,6 +484,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #define FLT128X_DECIMAL_DIG __FLT128X_DECIMAL_DIG__ #undef FLT128X_TRUE_MIN #define FLT128X_TRUE_MIN __FLT128X_DENORM_MIN__ +#if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L +#undef FLT128X_SNAN +#define FLT128X_SNAN (__builtin_nansf128x ("")) +#endif /* C2X */ #endif /* __FLT128X_MANT_DIG__. */ #endif /* __STDC_WANT_IEC_60559_TYPES_EXT__. */ @@ -537,6 +591,18 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #endif /* __STDC_WANT_IEC_60559_DFP_EXT__ || C2X. */ +#if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L + +/* Infinity in type _Decimal32. */ +#undef DEC_INFINITY +#define DEC_INFINITY (__builtin_infd32 ()) + +/* Quiet NaN in type _Decimal32. */ +#undef DEC_NAN +#define DEC_NAN (__builtin_nand32 ("")) + +#endif /* C2X */ + #endif /* __DEC32_MANT_DIG__ */ #endif /* _FLOAT_H___ */ -- cgit v1.1