From 7cf8aefccfe2f2ac63ce5f0791b53694cb38a54b Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Thu, 23 Jul 2009 18:38:22 +0000 Subject: [PATCH] cmath (abs(_Tp)): Add. 2009-07-23 Paolo Carlini * include/c_std/cmath (abs(_Tp)): Add. * include/c_global/cmath (abs(_Tp)): Likewise. * testsuite/26_numerics/headers/cmath/overloads.cc: Extend. From-SVN: r150022 --- libstdc++-v3/ChangeLog | 6 ++++++ libstdc++-v3/include/c_global/cmath | 6 ++++++ libstdc++-v3/include/c_std/cmath | 18 ++++++++++++------ .../26_numerics/headers/cmath/overloads.cc | 19 +++++++++++++++++++ 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index a7303bd928f..7ca37c7560b 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,9 @@ +2009-07-23 Paolo Carlini + + * include/c_std/cmath (abs(_Tp)): Add. + * include/c_global/cmath (abs(_Tp)): Likewise. + * testsuite/26_numerics/headers/cmath/overloads.cc: Extend. + 2009-07-23 Paolo Carlini * doc/html/ext/lwg-closed.html: Update to R65. diff --git a/libstdc++-v3/include/c_global/cmath b/libstdc++-v3/include/c_global/cmath index 9a63a011be4..a5c31c436d7 100644 --- a/libstdc++-v3/include/c_global/cmath +++ b/libstdc++-v3/include/c_global/cmath @@ -102,6 +102,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std) abs(long double __x) { return __builtin_fabsl(__x); } + template + inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, + double>::__type + abs(_Tp __x) + { return __builtin_fabs(__x); } + using ::acos; inline float diff --git a/libstdc++-v3/include/c_std/cmath b/libstdc++-v3/include/c_std/cmath index a0bebc9906f..3ee1393073f 100644 --- a/libstdc++-v3/include/c_std/cmath +++ b/libstdc++-v3/include/c_std/cmath @@ -93,6 +93,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std) abs(long double __x) { return __builtin_fabsl(__x); } + template + 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 @@ _GLIBCXX_BEGIN_NAMESPACE(std) { return __builtin_asinl(__x); } template - 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 @@ _GLIBCXX_BEGIN_NAMESPACE(std) { return __builtin_atanl(__x); } template - 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 @@ _GLIBCXX_BEGIN_NAMESPACE(std) template 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; diff --git a/libstdc++-v3/testsuite/26_numerics/headers/cmath/overloads.cc b/libstdc++-v3/testsuite/26_numerics/headers/cmath/overloads.cc index 4d41a9640b4..4418bc31b20 100644 --- a/libstdc++-v3/testsuite/26_numerics/headers/cmath/overloads.cc +++ b/libstdc++-v3/testsuite/26_numerics/headers/cmath/overloads.cc @@ -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 +// . + // PR 3181 // Origin: pete@toyon.com @@ -8,6 +26,7 @@ int main() int i = -1; int j = 9; double ans; + ans = std::abs(i); ans = std::acos(i); ans = std::asin(i); ans = std::atan(i);