SHA256
1
0
forked from pool/glibc
glibc/math-c++-compat.patch

127 lines
4.0 KiB
Diff
Raw Normal View History

2017-08-28 Gabriel F. T. Gomes <gftg@linux.vnet.ibm.com>
[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 <gftg@linux.vnet.ibm.com>
* 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 <gftg@linux.vnet.ibm.com>
* 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 <gftg@linux.vnet.ibm.com>
[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
@@ -442,8 +442,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 +474,32 @@ enum
# include <bits/iscanonical.h>
/* 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 +513,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 <class __T> 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. */