aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorGabriel Dos Reis <gdr@integrable-solutions.net>2003-05-11 09:07:17 +0000
committerGabriel Dos Reis <gdr@gcc.gnu.org>2003-05-11 09:07:17 +0000
commitcdc958d823386608ae27e2cda751711595dd838d (patch)
tree461d69e0788dca2c949e2cf6b54556cd5cdfdace /libstdc++-v3
parente1112e60cb9d8f22517caf306fa1a7e1584855e0 (diff)
downloadgcc-cdc958d823386608ae27e2cda751711595dd838d.zip
gcc-cdc958d823386608ae27e2cda751711595dd838d.tar.gz
gcc-cdc958d823386608ae27e2cda751711595dd838d.tar.bz2
re PR libstdc++/3181 (Unable to use sqrt,cos,sin,... with int argument.)
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. From-SVN: r66681
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/ChangeLog27
-rw-r--r--libstdc++-v3/include/bits/cpp_type_traits.h34
-rw-r--r--libstdc++-v3/include/c_std/std_cmath.h99
-rw-r--r--libstdc++-v3/testsuite/26_numerics/cmath/overloads.C27
4 files changed, 186 insertions, 1 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 2123a81..32dd575 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -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
diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h
index d66fe76..4151502 100644
--- a/libstdc++-v3/include/bits/cpp_type_traits.h
+++ b/libstdc++-v3/include/bits/cpp_type_traits.h
@@ -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
@@ -66,6 +66,38 @@
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
{
diff --git a/libstdc++-v3/include/c_std/std_cmath.h b/libstdc++-v3/include/c_std/std_cmath.h
index c9a88cf..04d300a 100644
--- a/libstdc++-v3/include/c_std/std_cmath.h
+++ b/libstdc++-v3/include/c_std/std_cmath.h
@@ -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
index 0000000..4d41a96
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/cmath/overloads.C
@@ -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);
+}