2017-09-22 Gabriel F. T. Gomes [BZ #22146] math/math.h: Let fpclassify use the builtin in C++ mode, even when optimazing for size. 2017-08-28 Gabriel F. T. Gomes [BZ #21930] * math/math.h [defined __cplusplus && defined __SUPPORT_SNAN__] (iszero): New C++ implementation that does not use fpclassify/__MATH_TG/__builtin_types_compatible_p, when signaling nans are enabled, since __builtin_types_compatible_p is a C-only feature. 2017-08-24 Gabriel F. T. Gomes * math/math.h [defined __cplusplus] (issignaling): In the long double case, call __issignalingl only if __NO_LONG_DOUBLE_MATH is not defined. Call __issignaling, otherwise. 2017-08-22 Gabriel F. T. Gomes * math/math.h [defined __cplusplus] (issignaling): Provide a C++ definition for issignaling that does not rely on __MATH_TG, since __MATH_TG uses __builtin_types_compatible_p, which is only available in C mode. 2017-08-18 Gabriel F. T. Gomes [BZ #21930] * math/math.h (isinf): Check if in C or C++ mode before using __builtin_types_compatible_p, since this is a C mode feature. Index: glibc-2.26/math/math.h =================================================================== --- glibc-2.26.orig/math/math.h +++ glibc-2.26/math/math.h @@ -402,7 +402,13 @@ enum /* Return number of classification appropriate for X. */ # if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__ \ - && !defined __OPTIMIZE_SIZE__ + && (!defined __OPTIMIZE_SIZE__ || defined __cplusplus) + /* The check for __cplusplus allows the use of the builtin, even + when optimization for size is on. This is provided for + libstdc++, only to let its configure test work when it is built + with -Os. No further use of this definition of fpclassify is + expected in C++ mode, since libstdc++ provides its own version + of fpclassify in cmath (which undefines fpclassify). */ # define fpclassify(x) __builtin_fpclassify (FP_NAN, FP_INFINITE, \ FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x) # else @@ -442,8 +448,12 @@ enum /* Return nonzero value if X is positive or negative infinity. */ # if __HAVE_DISTINCT_FLOAT128 && !__GNUC_PREREQ (7,0) \ - && !defined __SUPPORT_SNAN__ - /* __builtin_isinf_sign is broken for float128 only before GCC 7.0. */ + && !defined __SUPPORT_SNAN__ && !defined __cplusplus + /* Since __builtin_isinf_sign is broken for float128 before GCC 7.0, + use the helper function, __isinff128, with older compilers. This is + only provided for C mode, because in C++ mode, GCC has no support + for __builtin_types_compatible_p (and when in C++ mode, this macro is + not used anyway, because libstdc++ headers undefine it). */ # define isinf(x) \ (__builtin_types_compatible_p (__typeof (x), _Float128) \ ? __isinff128 (x) : __builtin_isinf_sign (x)) @@ -470,7 +480,32 @@ enum # include /* Return nonzero value if X is a signaling NaN. */ -# define issignaling(x) __MATH_TG ((x), __issignaling, (x)) +# ifndef __cplusplus +# define issignaling(x) __MATH_TG ((x), __issignaling, (x)) +# else + /* In C++ mode, __MATH_TG cannot be used, because it relies on + __builtin_types_compatible_p, which is a C-only builtin. On the + other hand, overloading provides the means to distinguish between + the floating-point types. The overloading resolution will match + the correct parameter (regardless of type qualifiers (i.e.: const + and volatile). */ +extern "C++" { +inline int issignaling (float __val) { return __issignalingf (__val); } +inline int issignaling (double __val) { return __issignaling (__val); } +inline int +issignaling (long double __val) +{ +# ifdef __NO_LONG_DOUBLE_MATH + return __issignaling (__val); +# else + return __issignalingl (__val); +# endif +} +# if __HAVE_DISTINCT_FLOAT128 +inline int issignaling (_Float128 __val) { return __issignalingf128 (__val); } +# endif +} /* extern C++ */ +# endif /* Return nonzero value if X is subnormal. */ # define issubnormal(x) (fpclassify (x) == FP_SUBNORMAL) @@ -484,15 +519,40 @@ enum # endif # else /* __cplusplus */ extern "C++" { +# ifdef __SUPPORT_SNAN__ +inline int +iszero (float __val) +{ + return __fpclassifyf (__val) == FP_ZERO; +} +inline int +iszero (double __val) +{ + return __fpclassify (__val) == FP_ZERO; +} +inline int +iszero (long double __val) +{ +# ifdef __NO_LONG_DOUBLE_MATH + return __fpclassify (__val) == FP_ZERO; +# else + return __fpclassifyl (__val) == FP_ZERO; +# endif +} +# if __HAVE_DISTINCT_FLOAT128 +inline int +iszero (_Float128 __val) +{ + return __fpclassifyf128 (__val) == FP_ZERO; +} +# endif +# else template inline bool iszero (__T __val) { -# ifdef __SUPPORT_SNAN__ - return fpclassify (__val) == FP_ZERO; -# else return __val == 0; -# endif } +# endif } /* extern C++ */ # endif /* __cplusplus */ #endif /* Use IEC_60559_BFP_EXT. */