OSDN Git Service

PR libstdc++/3181
authorgdr <gdr@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 11 May 2003 09:07:17 +0000 (09:07 +0000)
committergdr <gdr@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 11 May 2003 09:07:17 +0000 (09:07 +0000)
* include/c_std/std_cmath.h: #include <bits/cpp_type_traits.h>
(acos): Handle integer argument.
(asin): Likewise.
(atan): Likewise.
(atan2): Likewise.
(ceil): Likewise.
(cos): Likewise.
(cosh): Likewise.
(exp): Likewise.
(fabs): Likewise.
(floor): Likewise.
(frexp): Likewise.
(ldexp): Likewise.
(log): Likewise.
(log10): Likewise.
(sin): Likewise.
(sinh): Likewise.
(sqrt): Likewise.
(tan): Likewise.
(tanh): Likewise.
* include/bits/cpp_type_traits.h (__are_same<>): New traits.
(__enable_if): Likewise.
* testsuite/26_numerics/cmath/overloads.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@66681 138bc75d-0d04-0410-961f-82ee72b054a4

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/cpp_type_traits.h
libstdc++-v3/include/c_std/std_cmath.h
libstdc++-v3/testsuite/26_numerics/cmath/overloads.C [new file with mode: 0644]

index 2123a81..32dd575 100644 (file)
@@ -1,3 +1,30 @@
+2003-05-11  Gabriel Dos Reis <gdr@integrable-solutions.net>
+
+       PR libstdc++/3181
+       * include/c_std/std_cmath.h: #include <bits/cpp_type_traits.h>
+       (acos): Handle integer argument.
+       (asin): Likewise.
+       (atan): Likewise.
+       (atan2): Likewise.
+       (ceil): Likewise.
+       (cos): Likewise.
+       (cosh): Likewise.
+       (exp): Likewise.
+       (fabs): Likewise.
+       (floor): Likewise.
+       (frexp): Likewise.
+       (ldexp): Likewise.
+       (log): Likewise.
+       (log10): Likewise.
+       (sin): Likewise.
+       (sinh): Likewise.
+       (sqrt): Likewise.
+       (tan): Likewise.
+       (tanh): Likewise.
+       * include/bits/cpp_type_traits.h (__are_same<>): New traits.
+       (__enable_if): Likewise.
+       * testsuite/26_numerics/cmath/overloads.C: New test.
+       
 2003-05-10  Petur Runolfsson  <peturr02@ru.is>
 
        PR libstdc++/9027
index d66fe76..4151502 100644 (file)
@@ -1,6 +1,6 @@
 // The  -*- C++ -*- type traits classes for internal use in libstdc++
 
-// Copyright (C) 2000, 2001 Free Software Foundation, Inc.
+// Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
 
 namespace std
 {
+  // Compare for equality of types.
+  template<typename, typename>
+    struct __are_same
+    {
+      enum
+      {
+        _M_type = 0
+      };
+    };
+
+  template<typename _Tp>
+    struct __are_same<_Tp, _Tp>
+    {
+      enum
+      {
+        _M_type = 1
+      };
+    };
+
+  // Define a nested type if some predicate holds.
+  template<typename, bool>
+    struct __enable_if
+    {
+    };
+
+  template<typename _Tp>
+  struct __enable_if<_Tp, true>
+    {
+      typedef _Tp _M_type;
+    };
+
+  // Holds if the template-argument is a void type.
   template<typename _Tp>
     struct __is_void
     {
index c9a88cf..04d300a 100644 (file)
@@ -47,6 +47,7 @@
 #pragma GCC system_header
 
 #include <bits/c++config.h>
+#include <bits/cpp_type_traits.h>
 
 #include <math.h>
 
@@ -197,6 +198,13 @@ namespace std
   acos(long double __x) { return ::acos(static_cast<double>(__x)); }
 #endif
 
+  template<typename _Tp>
+    inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+    acos(_Tp __x)
+    {
+      return ::acos(static_cast<double>(__x));
+    }
+  
   using ::asin;
 
 #if _GLIBCPP_HAVE_ASINF
@@ -215,6 +223,11 @@ namespace std
   asin(long double __x) { return ::asin(static_cast<double>(__x)); }
 #endif
 
+  template<typename _Tp>
+    inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+    asin(_Tp __x)
+    { return ::asin(static_cast<double>(__x)); }
+
   using ::atan;
 
 #if _GLIBCPP_HAVE_ATANF
@@ -233,6 +246,11 @@ namespace std
   atan(long double __x) { return ::atan(static_cast<double>(__x)); }
 #endif
 
+  template<typename _Tp>
+    inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+    atan(_Tp __x)
+    { return ::atan(static_cast<double>(__x)); }
+  
   using ::atan2;
 
 #if _GLIBCPP_HAVE_ATAN2F
@@ -253,6 +271,12 @@ namespace std
   { return ::atan2(static_cast<double>(__y), static_cast<double>(__x)); }
 #endif
 
+  template<typename _Tp, typename _Up>
+    inline typename __enable_if<double, __is_integer<_Tp>::_M_type
+                                        && __is_integer<_Up>::_M_type>::_M_type
+    atan2(_Tp __x, _Up __y)
+    { return ::atan2(static_cast<double>(__x), static_cast<double>(__y)); }
+
   using ::ceil;
 
 #if _GLIBCPP_HAVE_CEILF
@@ -271,6 +295,11 @@ namespace std
   ceil(long double __x) { return ::ceil(static_cast<double>(__x)); }
 #endif
 
+  template<typename _Tp>
+    inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+    ceil(_Tp __x)
+    { return ::ceil(static_cast<double>(__x)); }
+  
   using ::cos;
 
   inline float
@@ -281,6 +310,11 @@ namespace std
   cos(long double __x)
   { return __builtin_cosl(__x); }
 
+  template<typename _Tp>
+    inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+    cos(_Tp __x)
+    { return __builtin_cos(__x); }
+
   using ::cosh;
 
 #if _GLIBCPP_HAVE_COSHF
@@ -299,6 +333,11 @@ namespace std
   cosh(long double __x) { return ::cosh(static_cast<double>(__x)); }
 #endif
 
+  template<typename _Tp>
+    inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+    cosh(_Tp __x)
+    { return ::cosh(static_cast<double>(__x)); }
+
   using ::exp;
 
 #if _GLIBCPP_HAVE_EXPF
@@ -317,6 +356,11 @@ namespace std
   exp(long double __x) { return ::exp(static_cast<double>(__x)); }
 #endif
 
+  template<typename _Tp>
+    inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+    exp(_Tp __x)
+    { return ::exp(static_cast<double>(__x)); }
+  
   using ::fabs;
 
   inline float
@@ -327,6 +371,11 @@ namespace std
   fabs(long double __x)
   { return __builtin_fabsl(__x); }
 
+  template<typename _Tp>
+    inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+    fabs(_Tp __x)
+    { return __builtin_fabs(__x); }
+
   using ::floor;
 
 #if _GLIBCPP_HAVE_FLOORF
@@ -345,6 +394,11 @@ namespace std
   floor(long double __x) { return ::floor(static_cast<double>(__x)); }
 #endif
 
+  template<typename _Tp>
+    inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+    floor(_Tp __x)
+    { return ::floor(static_cast<double>(__x)); }
+  
   using ::fmod;
 
 #if _GLIBCPP_HAVE_FMODF
@@ -384,6 +438,11 @@ namespace std
   { return ::frexp(static_cast<double>(__x), __exp); }
 #endif
 
+  template<typename _Tp>
+    inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+    frexp(_Tp __x, int* __exp)
+    { return ::frexp(static_cast<double>(__x), __exp); }
+  
   using ::ldexp;
 
 #if _GLIBCPP_HAVE_LDEXPF
@@ -404,6 +463,11 @@ namespace std
   { return ::ldexp(static_cast<double>(__x), __exp); }
 #endif
 
+  template<typename _Tp>
+  inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+  ldexp(_Tp __x, int __exp)
+  { return ::ldexp(static_cast<double>(__x), __exp); }
+
   using ::log;
 
 #if _GLIBCPP_HAVE_LOGF
@@ -422,6 +486,11 @@ namespace std
   log(long double __x) { return ::log(static_cast<double>(__x)); }
 #endif
 
+  template<typename _Tp>
+    inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+    log(_Tp __x)
+    { return ::log(static_cast<double>(__x)); }
+  
   using ::log10;
 
 #if _GLIBCPP_HAVE_LOG10F
@@ -440,6 +509,11 @@ namespace std
   log10(long double __x) { return ::log10(static_cast<double>(__x)); }
 #endif
 
+  template<typename _Tp>
+    inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+    log10(_Tp __x)
+    { return ::log10(static_cast<double>(__x)); }
+  
   using ::modf;
 
 #if _GLIBCPP_HAVE_MODFF
@@ -521,6 +595,11 @@ namespace std
   sin(long double __x)
   { return __builtin_sinl(__x); }
 
+  template<typename _Tp>
+    inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+    sin(_Tp __x)
+    { return __builtin_sin(__x); }
+
   using ::sinh;
 
 #if _GLIBCPP_HAVE_SINHF
@@ -539,6 +618,11 @@ namespace std
   sinh(long double __x) { return ::sinh(static_cast<double>(__x)); }
 #endif
 
+  template<typename _Tp>
+    inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+    sinh(_Tp __x)
+    { return ::sinh(static_cast<_Tp>(__x)); }
+  
   using ::sqrt;
 
   inline float
@@ -549,6 +633,11 @@ namespace std
   sqrt(long double __x)
   { return __builtin_sqrtl(__x); }
 
+  template<typename _Tp>
+    inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+    sqrt(_Tp __x)
+    { return __builtin_sqrt(__x); }
+  
   using ::tan;
 
 #if _GLIBCPP_HAVE_TANF
@@ -567,6 +656,11 @@ namespace std
   tan(long double __x) { return ::tan(static_cast<double>(__x)); }
 #endif
 
+  template<typename _Tp>
+    inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+    tan(_Tp __x)
+    { return ::tan(static_cast<double>(__x)); }
+  
   using ::tanh;
 
 #if _GLIBCPP_HAVE_TANHF
@@ -584,6 +678,11 @@ namespace std
   inline long double 
   tanh(long double __x) { return ::tanh(static_cast<double>(__x)); }
 #endif
+
+  template<typename _Tp>
+    inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+    tanh(_Tp __x)
+    { return ::tanh(static_cast<double>(__x)); }
 } 
 
 
diff --git a/libstdc++-v3/testsuite/26_numerics/cmath/overloads.C b/libstdc++-v3/testsuite/26_numerics/cmath/overloads.C
new file mode 100644 (file)
index 0000000..4d41a96
--- /dev/null
@@ -0,0 +1,27 @@
+// PR 3181
+// Origin: pete@toyon.com
+
+#include <cmath>
+
+int main()
+{
+  int i = -1;
+  int j = 9;
+  double ans;
+  ans = std::acos(i);
+  ans = std::asin(i);
+  ans = std::atan(i);
+  ans = std::atan2(i, j);
+  ans = std::cos(i);
+  ans = std::cosh(i);
+  ans = std::exp(i);
+  ans = std::fabs(i);
+  ans = std::floor(i);
+  ans = std::log(i);
+  ans = std::log10(i);
+  ans = std::sqrt(i);
+  ans = std::sin(i);
+  ans = std::sinh(j);
+  ans = std::tan(i);
+  ans = std::tanh(i);
+}