From cdc958d823386608ae27e2cda751711595dd838d Mon Sep 17 00:00:00 2001 From: Gabriel Dos Reis Date: Sun, 11 May 2003 09:07:17 +0000 Subject: [PATCH] re PR libstdc++/3181 (Unable to use sqrt,cos,sin,... with int argument.) PR libstdc++/3181 * include/c_std/std_cmath.h: #include (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 --- libstdc++-v3/ChangeLog | 27 +++++ libstdc++-v3/include/bits/cpp_type_traits.h | 34 ++++++- libstdc++-v3/include/c_std/std_cmath.h | 99 +++++++++++++++++++ .../testsuite/26_numerics/cmath/overloads.C | 27 +++++ 4 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 libstdc++-v3/testsuite/26_numerics/cmath/overloads.C diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 2123a81de7a4..32dd57510226 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,30 @@ +2003-05-11 Gabriel Dos Reis + + PR libstdc++/3181 + * include/c_std/std_cmath.h: #include + (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 PR libstdc++/9027 diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h index d66fe7638410..415150275c48 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 + struct __are_same + { + enum + { + _M_type = 0 + }; + }; + + template + struct __are_same<_Tp, _Tp> + { + enum + { + _M_type = 1 + }; + }; + + // Define a nested type if some predicate holds. + template + struct __enable_if + { + }; + + template + struct __enable_if<_Tp, true> + { + typedef _Tp _M_type; + }; + + // Holds if the template-argument is a void type. template struct __is_void { diff --git a/libstdc++-v3/include/c_std/std_cmath.h b/libstdc++-v3/include/c_std/std_cmath.h index c9a88cfb7945..04d300a01c6b 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 +#include #include @@ -197,6 +198,13 @@ namespace std acos(long double __x) { return ::acos(static_cast(__x)); } #endif + template + inline typename __enable_if::_M_type>::_M_type + acos(_Tp __x) + { + return ::acos(static_cast(__x)); + } + using ::asin; #if _GLIBCPP_HAVE_ASINF @@ -215,6 +223,11 @@ namespace std asin(long double __x) { return ::asin(static_cast(__x)); } #endif + template + inline typename __enable_if::_M_type>::_M_type + asin(_Tp __x) + { return ::asin(static_cast(__x)); } + using ::atan; #if _GLIBCPP_HAVE_ATANF @@ -233,6 +246,11 @@ namespace std atan(long double __x) { return ::atan(static_cast(__x)); } #endif + template + inline typename __enable_if::_M_type>::_M_type + atan(_Tp __x) + { return ::atan(static_cast(__x)); } + using ::atan2; #if _GLIBCPP_HAVE_ATAN2F @@ -253,6 +271,12 @@ namespace std { return ::atan2(static_cast(__y), static_cast(__x)); } #endif + template + inline typename __enable_if::_M_type + && __is_integer<_Up>::_M_type>::_M_type + atan2(_Tp __x, _Up __y) + { return ::atan2(static_cast(__x), static_cast(__y)); } + using ::ceil; #if _GLIBCPP_HAVE_CEILF @@ -271,6 +295,11 @@ namespace std ceil(long double __x) { return ::ceil(static_cast(__x)); } #endif + template + inline typename __enable_if::_M_type>::_M_type + ceil(_Tp __x) + { return ::ceil(static_cast(__x)); } + using ::cos; inline float @@ -281,6 +310,11 @@ namespace std cos(long double __x) { return __builtin_cosl(__x); } + template + inline typename __enable_if::_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(__x)); } #endif + template + inline typename __enable_if::_M_type>::_M_type + cosh(_Tp __x) + { return ::cosh(static_cast(__x)); } + using ::exp; #if _GLIBCPP_HAVE_EXPF @@ -317,6 +356,11 @@ namespace std exp(long double __x) { return ::exp(static_cast(__x)); } #endif + template + inline typename __enable_if::_M_type>::_M_type + exp(_Tp __x) + { return ::exp(static_cast(__x)); } + using ::fabs; inline float @@ -327,6 +371,11 @@ namespace std fabs(long double __x) { return __builtin_fabsl(__x); } + template + inline typename __enable_if::_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(__x)); } #endif + template + inline typename __enable_if::_M_type>::_M_type + floor(_Tp __x) + { return ::floor(static_cast(__x)); } + using ::fmod; #if _GLIBCPP_HAVE_FMODF @@ -384,6 +438,11 @@ namespace std { return ::frexp(static_cast(__x), __exp); } #endif + template + inline typename __enable_if::_M_type>::_M_type + frexp(_Tp __x, int* __exp) + { return ::frexp(static_cast(__x), __exp); } + using ::ldexp; #if _GLIBCPP_HAVE_LDEXPF @@ -404,6 +463,11 @@ namespace std { return ::ldexp(static_cast(__x), __exp); } #endif + template + inline typename __enable_if::_M_type>::_M_type + ldexp(_Tp __x, int __exp) + { return ::ldexp(static_cast(__x), __exp); } + using ::log; #if _GLIBCPP_HAVE_LOGF @@ -422,6 +486,11 @@ namespace std log(long double __x) { return ::log(static_cast(__x)); } #endif + template + inline typename __enable_if::_M_type>::_M_type + log(_Tp __x) + { return ::log(static_cast(__x)); } + using ::log10; #if _GLIBCPP_HAVE_LOG10F @@ -440,6 +509,11 @@ namespace std log10(long double __x) { return ::log10(static_cast(__x)); } #endif + template + inline typename __enable_if::_M_type>::_M_type + log10(_Tp __x) + { return ::log10(static_cast(__x)); } + using ::modf; #if _GLIBCPP_HAVE_MODFF @@ -521,6 +595,11 @@ namespace std sin(long double __x) { return __builtin_sinl(__x); } + template + inline typename __enable_if::_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(__x)); } #endif + template + inline typename __enable_if::_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 + inline typename __enable_if::_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(__x)); } #endif + template + inline typename __enable_if::_M_type>::_M_type + tan(_Tp __x) + { return ::tan(static_cast(__x)); } + using ::tanh; #if _GLIBCPP_HAVE_TANHF @@ -584,6 +678,11 @@ namespace std inline long double tanh(long double __x) { return ::tanh(static_cast(__x)); } #endif + + template + inline typename __enable_if::_M_type>::_M_type + tanh(_Tp __x) + { return ::tanh(static_cast(__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 000000000000..4d41a9640b47 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/cmath/overloads.C @@ -0,0 +1,27 @@ +// PR 3181 +// Origin: pete@toyon.com + +#include + +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); +} -- 2.39.5