[cfe-commits] [libcxx] r172461 - in /libcxx/trunk: include/cmath test/numerics/c.math/cmath.pass.cpp

Howard Hinnant hhinnant at apple.com
Mon Jan 14 12:56:22 PST 2013


Author: hhinnant
Date: Mon Jan 14 14:56:22 2013
New Revision: 172461

URL: http://llvm.org/viewvc/llvm-project?rev=172461&view=rev
Log:
Make <cmath> classification macros work with integral types.

Modified:
    libcxx/trunk/include/cmath
    libcxx/trunk/test/numerics/c.math/cmath.pass.cpp

Modified: libcxx/trunk/include/cmath
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/cmath?rev=172461&r1=172460&r2=172461&view=diff
==============================================================================
--- libcxx/trunk/include/cmath (original)
+++ libcxx/trunk/include/cmath Mon Jan 14 14:56:22 2013
@@ -137,21 +137,21 @@
 
 //  C99
 
-bool signbit(floating_point x);
+bool signbit(arithmetic x);
 
-int fpclassify(floating_point x);
+int fpclassify(arithmetic x);
 
-bool isfinite(floating_point x);
-bool isinf(floating_point x);
-bool isnan(floating_point x);
-bool isnormal(floating_point x);
-
-bool isgreater(floating_point x, floating_point y);
-bool isgreaterequal(floating_point x, floating_point y);
-bool isless(floating_point x, floating_point y);
-bool islessequal(floating_point x, floating_point y);
-bool islessgreater(floating_point x, floating_point y);
-bool isunordered(floating_point x, floating_point y);
+bool isfinite(arithmetic x);
+bool isinf(arithmetic x);
+bool isnan(arithmetic x);
+bool isnormal(arithmetic x);
+
+bool isgreater(arithmetic x, arithmetic y);
+bool isgreaterequal(arithmetic x, arithmetic y);
+bool isless(arithmetic x, arithmetic y);
+bool islessequal(arithmetic x, arithmetic y);
+bool islessgreater(arithmetic x, arithmetic y);
+bool isunordered(arithmetic x, arithmetic y);
 
 floating_point acosh (arithmetic x);
 float          acoshf(float x);
@@ -325,10 +325,10 @@
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type
+typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
 signbit(_A1 __x) _NOEXCEPT
 {
-    return __libcpp_signbit(__x);
+    return __libcpp_signbit((typename std::__promote<_A1>::type)__x);
 }
 
 #endif  // signbit
@@ -349,10 +349,10 @@
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_floating_point<_A1>::value, int>::type
+typename std::enable_if<std::is_arithmetic<_A1>::value, int>::type
 fpclassify(_A1 __x) _NOEXCEPT
 {
-    return __libcpp_fpclassify(__x);
+    return __libcpp_fpclassify((typename std::__promote<_A1>::type)__x);
 }
 
 #endif  // fpclassify
@@ -373,10 +373,10 @@
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type
+typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
 isfinite(_A1 __x) _NOEXCEPT
 {
-    return __libcpp_isfinite(__x);
+    return __libcpp_isfinite((typename std::__promote<_A1>::type)__x);
 }
 
 #endif  // isfinite
@@ -397,10 +397,10 @@
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type
+typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
 isinf(_A1 __x) _NOEXCEPT
 {
-    return __libcpp_isinf(__x);
+    return __libcpp_isinf((typename std::__promote<_A1>::type)__x);
 }
 
 #endif  // isinf
@@ -421,10 +421,10 @@
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type
+typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
 isnan(_A1 __x) _NOEXCEPT
 {
-    return __libcpp_isnan(__x);
+    return __libcpp_isnan((typename std::__promote<_A1>::type)__x);
 }
 
 #endif  // isnan
@@ -445,10 +445,10 @@
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type
+typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
 isnormal(_A1 __x) _NOEXCEPT
 {
-    return __libcpp_isnormal(__x);
+    return __libcpp_isnormal((typename std::__promote<_A1>::type)__x);
 }
 
 #endif  // isnormal
@@ -471,13 +471,14 @@
 inline _LIBCPP_INLINE_VISIBILITY
 typename std::enable_if
 <
-    std::is_floating_point<_A1>::value &&
-    std::is_floating_point<_A2>::value,
+    std::is_arithmetic<_A1>::value &&
+    std::is_arithmetic<_A2>::value,
     bool
 >::type
 isgreater(_A1 __x, _A2 __y) _NOEXCEPT
 {
-    return __libcpp_isgreater(__x, __y);
+    typedef typename std::__promote<_A1, _A2>::type type;
+    return __libcpp_isgreater((type)__x, (type)__y);
 }
 
 #endif  // isgreater
@@ -500,13 +501,14 @@
 inline _LIBCPP_INLINE_VISIBILITY
 typename std::enable_if
 <
-    std::is_floating_point<_A1>::value &&
-    std::is_floating_point<_A2>::value,
+    std::is_arithmetic<_A1>::value &&
+    std::is_arithmetic<_A2>::value,
     bool
 >::type
 isgreaterequal(_A1 __x, _A2 __y) _NOEXCEPT
 {
-    return __libcpp_isgreaterequal(__x, __y);
+    typedef typename std::__promote<_A1, _A2>::type type;
+    return __libcpp_isgreaterequal((type)__x, (type)__y);
 }
 
 #endif  // isgreaterequal
@@ -529,13 +531,14 @@
 inline _LIBCPP_INLINE_VISIBILITY
 typename std::enable_if
 <
-    std::is_floating_point<_A1>::value &&
-    std::is_floating_point<_A2>::value,
+    std::is_arithmetic<_A1>::value &&
+    std::is_arithmetic<_A2>::value,
     bool
 >::type
 isless(_A1 __x, _A2 __y) _NOEXCEPT
 {
-    return __libcpp_isless(__x, __y);
+    typedef typename std::__promote<_A1, _A2>::type type;
+    return __libcpp_isless((type)__x, (type)__y);
 }
 
 #endif  // isless
@@ -558,13 +561,14 @@
 inline _LIBCPP_INLINE_VISIBILITY
 typename std::enable_if
 <
-    std::is_floating_point<_A1>::value &&
-    std::is_floating_point<_A2>::value,
+    std::is_arithmetic<_A1>::value &&
+    std::is_arithmetic<_A2>::value,
     bool
 >::type
 islessequal(_A1 __x, _A2 __y) _NOEXCEPT
 {
-    return __libcpp_islessequal(__x, __y);
+    typedef typename std::__promote<_A1, _A2>::type type;
+    return __libcpp_islessequal((type)__x, (type)__y);
 }
 
 #endif  // islessequal
@@ -587,13 +591,14 @@
 inline _LIBCPP_INLINE_VISIBILITY
 typename std::enable_if
 <
-    std::is_floating_point<_A1>::value &&
-    std::is_floating_point<_A2>::value,
+    std::is_arithmetic<_A1>::value &&
+    std::is_arithmetic<_A2>::value,
     bool
 >::type
 islessgreater(_A1 __x, _A2 __y) _NOEXCEPT
 {
-    return __libcpp_islessgreater(__x, __y);
+    typedef typename std::__promote<_A1, _A2>::type type;
+    return __libcpp_islessgreater((type)__x, (type)__y);
 }
 
 #endif  // islessgreater
@@ -616,13 +621,14 @@
 inline _LIBCPP_INLINE_VISIBILITY
 typename std::enable_if
 <
-    std::is_floating_point<_A1>::value &&
-    std::is_floating_point<_A2>::value,
+    std::is_arithmetic<_A1>::value &&
+    std::is_arithmetic<_A2>::value,
     bool
 >::type
 isunordered(_A1 __x, _A2 __y) _NOEXCEPT
 {
-    return __libcpp_isunordered(__x, __y);
+    typedef typename std::__promote<_A1, _A2>::type type;
+    return __libcpp_isunordered((type)__x, (type)__y);
 }
 
 #endif  // isunordered

Modified: libcxx/trunk/test/numerics/c.math/cmath.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/c.math/cmath.pass.cpp?rev=172461&r1=172460&r2=172461&view=diff
==============================================================================
--- libcxx/trunk/test/numerics/c.math/cmath.pass.cpp (original)
+++ libcxx/trunk/test/numerics/c.math/cmath.pass.cpp Mon Jan 14 14:56:22 2013
@@ -433,6 +433,7 @@
 #endif
     static_assert((std::is_same<decltype(std::signbit((float)0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::signbit((double)0)), bool>::value), "");
+    static_assert((std::is_same<decltype(std::signbit(0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::signbit((long double)0)), bool>::value), "");
     assert(std::signbit(-1.0) == true);
 }
@@ -444,6 +445,7 @@
 #endif
     static_assert((std::is_same<decltype(std::fpclassify((float)0)), int>::value), "");
     static_assert((std::is_same<decltype(std::fpclassify((double)0)), int>::value), "");
+    static_assert((std::is_same<decltype(std::fpclassify(0)), int>::value), "");
     static_assert((std::is_same<decltype(std::fpclassify((long double)0)), int>::value), "");
     assert(std::fpclassify(-1.0) == FP_NORMAL);
 }
@@ -455,6 +457,7 @@
 #endif
     static_assert((std::is_same<decltype(std::isfinite((float)0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::isfinite((double)0)), bool>::value), "");
+    static_assert((std::is_same<decltype(std::isfinite(0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::isfinite((long double)0)), bool>::value), "");
     assert(std::isfinite(-1.0) == true);
 }
@@ -466,6 +469,7 @@
 #endif
     static_assert((std::is_same<decltype(std::isinf((float)0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::isinf((double)0)), bool>::value), "");
+    static_assert((std::is_same<decltype(std::isinf(0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::isinf((long double)0)), bool>::value), "");
     assert(std::isinf(-1.0) == false);
 }
@@ -477,6 +481,7 @@
 #endif
     static_assert((std::is_same<decltype(std::isnan((float)0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::isnan((double)0)), bool>::value), "");
+    static_assert((std::is_same<decltype(std::isnan(0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::isnan((long double)0)), bool>::value), "");
     assert(std::isnan(-1.0) == false);
 }
@@ -488,6 +493,7 @@
 #endif
     static_assert((std::is_same<decltype(std::isnormal((float)0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::isnormal((double)0)), bool>::value), "");
+    static_assert((std::is_same<decltype(std::isnormal(0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::isnormal((long double)0)), bool>::value), "");
     assert(std::isnormal(-1.0) == true);
 }
@@ -502,6 +508,7 @@
     static_assert((std::is_same<decltype(std::isgreater((float)0, (long double)0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::isgreater((double)0, (float)0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::isgreater((double)0, (double)0)), bool>::value), "");
+    static_assert((std::is_same<decltype(std::isgreater(0, (double)0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::isgreater((double)0, (long double)0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::isgreater((long double)0, (float)0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::isgreater((long double)0, (double)0)), bool>::value), "");
@@ -519,6 +526,7 @@
     static_assert((std::is_same<decltype(std::isgreaterequal((float)0, (long double)0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::isgreaterequal((double)0, (float)0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::isgreaterequal((double)0, (double)0)), bool>::value), "");
+    static_assert((std::is_same<decltype(std::isgreaterequal(0, (double)0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::isgreaterequal((double)0, (long double)0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::isgreaterequal((long double)0, (float)0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::isgreaterequal((long double)0, (double)0)), bool>::value), "");
@@ -536,6 +544,7 @@
     static_assert((std::is_same<decltype(std::isless((float)0, (long double)0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::isless((double)0, (float)0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::isless((double)0, (double)0)), bool>::value), "");
+    static_assert((std::is_same<decltype(std::isless(0, (double)0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::isless((double)0, (long double)0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::isless((long double)0, (float)0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::isless((long double)0, (double)0)), bool>::value), "");
@@ -553,6 +562,7 @@
     static_assert((std::is_same<decltype(std::islessequal((float)0, (long double)0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::islessequal((double)0, (float)0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::islessequal((double)0, (double)0)), bool>::value), "");
+    static_assert((std::is_same<decltype(std::islessequal(0, (double)0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::islessequal((double)0, (long double)0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::islessequal((long double)0, (float)0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::islessequal((long double)0, (double)0)), bool>::value), "");
@@ -570,6 +580,7 @@
     static_assert((std::is_same<decltype(std::islessgreater((float)0, (long double)0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::islessgreater((double)0, (float)0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::islessgreater((double)0, (double)0)), bool>::value), "");
+    static_assert((std::is_same<decltype(std::islessgreater(0, (double)0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::islessgreater((double)0, (long double)0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::islessgreater((long double)0, (float)0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::islessgreater((long double)0, (double)0)), bool>::value), "");
@@ -587,6 +598,7 @@
     static_assert((std::is_same<decltype(std::isunordered((float)0, (long double)0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::isunordered((double)0, (float)0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::isunordered((double)0, (double)0)), bool>::value), "");
+    static_assert((std::is_same<decltype(std::isunordered(0, (double)0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::isunordered((double)0, (long double)0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::isunordered((long double)0, (float)0)), bool>::value), "");
     static_assert((std::is_same<decltype(std::isunordered((long double)0, (double)0)), bool>::value), "");





More information about the cfe-commits mailing list