This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[v3] Extend the fix for libstdc++/3181 to std::abs
- From: Paolo Carlini <paolo dot carlini at oracle dot com>
- To: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Cc: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Thu, 23 Jul 2009 20:41:47 +0200
- Subject: [v3] Extend the fix for libstdc++/3181 to std::abs
Hi,
in the original fix, std::abs was missing, and for C++0x is necessary
anyway. Probably we didn't notice earlier because <cstdlib> is often
also included... Committed to mainline.
Paolo.
///////////////
2009-07-23 Paolo Carlini <paolo.carlini@oracle.com>
* include/c_std/cmath (abs(_Tp)): Add.
* include/c_global/cmath (abs(_Tp)): Likewise.
* testsuite/26_numerics/headers/cmath/overloads.cc: Extend.
Index: include/c_std/cmath
===================================================================
--- include/c_std/cmath (revision 150018)
+++ include/c_std/cmath (working copy)
@@ -93,6 +93,12 @@
abs(long double __x)
{ return __builtin_fabsl(__x); }
+ template<typename _Tp>
+ inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
+ double>::__type
+ abs(_Tp __x)
+ { return __builtin_fabs(__x); }
+
using ::acos;
inline float
@@ -120,8 +126,8 @@
{ return __builtin_asinl(__x); }
template<typename _Tp>
- inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
- double>::__type
+ inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
+ double>::__type
asin(_Tp __x)
{ return __builtin_asin(__x); }
@@ -136,8 +142,8 @@
{ return __builtin_atanl(__x); }
template<typename _Tp>
- inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
- double>::__type
+ inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
+ double>::__type
atan(_Tp __x)
{ return __builtin_atan(__x); }
@@ -293,8 +299,8 @@
template<typename _Tp>
inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
double>::__type
- ldexp(_Tp __x, int __exp)
- { return __builtin_ldexp(__x, __exp); }
+ ldexp(_Tp __x, int __exp)
+ { return __builtin_ldexp(__x, __exp); }
using ::log;
Index: include/c_global/cmath
===================================================================
--- include/c_global/cmath (revision 150018)
+++ include/c_global/cmath (working copy)
@@ -102,6 +102,12 @@
abs(long double __x)
{ return __builtin_fabsl(__x); }
+ template<typename _Tp>
+ inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
+ double>::__type
+ abs(_Tp __x)
+ { return __builtin_fabs(__x); }
+
using ::acos;
inline float
Index: testsuite/26_numerics/headers/cmath/overloads.cc
===================================================================
--- testsuite/26_numerics/headers/cmath/overloads.cc (revision 150018)
+++ testsuite/26_numerics/headers/cmath/overloads.cc (working copy)
@@ -1,3 +1,21 @@
+// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009
+// 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
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
// PR 3181
// Origin: pete@toyon.com
@@ -8,6 +26,7 @@
int i = -1;
int j = 9;
double ans;
+ ans = std::abs(i);
ans = std::acos(i);
ans = std::asin(i);
ans = std::atan(i);