This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3] Implement DR 550 (Ready)


Hi,

tested x86_64-linux, committed to mainline.

Paolo.

/////////////////////
2008-05-26  Paolo Carlini  <paolo.carlini@oracle.com>

	* include/c_global/cmath (pow(float, int), pow(double, int),
	pow(long double, int)): Do not define in C++0x mode, per DR 550.
	* include/tr1_impl/cmath (pow): Do not bring in unconditionally
	from namespace std.
	* include/tr1/cmath (pow(double, double), pow(float, float),
	pow(long double, long double), pow(_Tp, _Up)): Define.
	* include/tr1/complex (pow): Do not bring in from namespace std.
	(pow(const std::complex<_Tp>&, int), pow(const std::complex<_Tp>&,
	const _Tp&), pow(const _Tp&, const std::complex<_Tp>&),
	pow(const std::complex<_Tp>&, const std::complex<_Tp>&)): Define.
	* include/tr1_impl/complex (pow(const std::complex<_Tp>&,
	const _Up&), pow(const _Tp&, const std::complex<_Up>&),
	pow(const std::complex<_Tp>&, const std::complex<_Up>&)): Always
	define.
	* doc/xml/manual/intro.xml: Add an entry for DR 550.
	* testsuite/26_numerics/headers/cmath/dr550.cc: New.
	* testsuite/tr1/8_c_compatibility/cmath/overloads.cc: Adjust.
Index: doc/xml/manual/intro.xml
===================================================================
--- doc/xml/manual/intro.xml	(revision 135953)
+++ doc/xml/manual/intro.xml	(working copy)
@@ -611,6 +611,12 @@
     <listitem><para>Follow the straightforward proposed resolution.
     </para></listitem></varlistentry>
 
+    <varlistentry><term><ulink url="../ext/lwg-active.html#550">550</ulink>:
+        <emphasis>What should the return type of pow(float,int) be?</emphasis>
+    </term>
+    <listitem><para>In C++0x mode, remove the pow(float,int), etc., signatures.
+    </para></listitem></varlistentry>
+
     <varlistentry><term><ulink url="../ext/lwg-defects.html#586">586</ulink>:
         <emphasis>string inserter not a formatted function</emphasis>
     </term>
Index: include/tr1_impl/cmath
===================================================================
--- include/tr1_impl/cmath	(revision 135953)
+++ include/tr1_impl/cmath	(working copy)
@@ -763,7 +763,9 @@
       return nexttoward(__type(__x), __y);
     }
 
-  using std::pow;
+  // DR 550. What should the return type of pow(float,int) be?
+  // NB: C++0x and TR1 != C++03.
+  //   using std::pow;
 
   inline float
   remainder(float __x, float __y)
Index: include/tr1_impl/complex
===================================================================
--- include/tr1_impl/complex	(revision 135953)
+++ include/tr1_impl/complex	(working copy)
@@ -301,12 +301,11 @@
     fabs(const std::complex<_Tp>& __z)
     { return std::abs(__z); }
 
-
+  /// Additional overloads [8.1.9].
 #if (defined(_GLIBCXX_INCLUDE_AS_CXX0X) \
      || (defined(_GLIBCXX_INCLUDE_AS_TR1) \
 	 && !defined(__GXX_EXPERIMENTAL_CXX0X__)))
 
-  /// Additional overloads [8.1.9].
   template<typename _Tp>
     inline typename __gnu_cxx::__promote<_Tp>::__type
     arg(_Tp __x)
@@ -338,6 +337,8 @@
     real(_Tp __x)
     { return __x; }
 
+#endif
+
   template<typename _Tp, typename _Up>
     inline std::complex<typename __gnu_cxx::__promote_2<_Tp, _Up>::__type>
     pow(const std::complex<_Tp>& __x, const _Up& __y)
@@ -363,7 +364,5 @@
 		      std::complex<__type>(__y));
     }
 
-#endif
-
 _GLIBCXX_END_NAMESPACE_TR1
 }
Index: include/c_global/cmath
===================================================================
--- include/c_global/cmath	(revision 135953)
+++ include/c_global/cmath	(working copy)
@@ -367,7 +367,9 @@
   pow(long double __x, long double __y)
   { return __builtin_powl(__x, __y); }
 
-  // DR 550.
+#ifndef __GXX_EXPERIMENTAL_CXX0X__
+  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+  // DR 550. What should the return type of pow(float,int) be?
   inline double
   pow(double __x, int __i)
   { return __builtin_powi(__x, __i); }
@@ -379,6 +381,7 @@
   inline long double
   pow(long double __x, int __n)
   { return __builtin_powil(__x, __n); }
+#endif
 
   template<typename _Tp, typename _Up>
     inline
Index: include/tr1/cmath
===================================================================
--- include/tr1/cmath	(revision 135953)
+++ include/tr1/cmath	(working copy)
@@ -56,6 +56,34 @@
 #  undef _GLIBCXX_INCLUDE_AS_TR1
 #endif
 
+namespace std
+{
+namespace tr1
+{
+  // DR 550. What should the return type of pow(float,int) be?
+  // NB: C++0x and TR1 != C++03.
+  inline double
+  pow(double __x, double __y)
+  { return std::pow(__x, __y); }
+
+  inline float
+  pow(float __x, float __y)
+  { return std::pow(__x, __y); }
+
+  inline long double
+  pow(long double __x, long double __y)
+  { return std::pow(__x, __y); }
+
+  template<typename _Tp, typename _Up>
+    inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
+    pow(_Tp __x, _Up __y)
+    {
+      typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
+      return std::pow(__type(__x), __type(__y));
+    }
+}
+}
+
 #include <bits/stl_algobase.h>
 #include <limits>
 #include <tr1/type_traits>
Index: include/tr1/complex
===================================================================
--- include/tr1/complex	(revision 135953)
+++ include/tr1/complex	(working copy)
@@ -75,9 +75,27 @@
     }
 
   using std::real;
-  using std::pow;
+
+  template<typename _Tp>
+    inline std::complex<_Tp>
+    pow(const std::complex<_Tp>& __x, int __n)
+    { return std::pow(__x, __n); }
+
+  template<typename _Tp>
+    inline std::complex<_Tp>
+    pow(const std::complex<_Tp>& __x, const _Tp& __y)
+    { return std::pow(__x, __y); }
+
+  template<typename _Tp>
+    inline std::complex<_Tp>
+    pow(const _Tp& __x, const std::complex<_Tp>& __y)
+    { return std::pow(__x, __y); }
+
+  template<typename _Tp>
+    inline std::complex<_Tp>
+    pow(const std::complex<_Tp>& __x, const std::complex<_Tp>& __y)
+    { return std::pow(__x, __y); }
 }
 }
 
 #endif // _GLIBCXX_TR1_COMPLEX
-
Index: testsuite/26_numerics/headers/cmath/dr550.cc
===================================================================
--- testsuite/26_numerics/headers/cmath/dr550.cc	(revision 0)
+++ testsuite/26_numerics/headers/cmath/dr550.cc	(revision 0)
@@ -0,0 +1,47 @@
+// { dg-options "-std=gnu++0x" }
+// 2008-05-26  Paolo Carlini  <paolo.carlini@oracle.com>
+//
+// Copyright (C) 2008 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+#include <cmath>
+#include <testsuite_hooks.h>
+#include <testsuite_tr1.h>
+
+// DR 550. What should the return type of pow(float,int) be?
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+  using __gnu_test::check_ret_type;
+
+  const int          i1 = 1;
+  const float        f1 = 1.0f;
+  const double       d1 = 1.0;
+  const long double ld1 = 1.0l;
+
+  check_ret_type<double>(std::pow(f1, i1));
+  VERIFY( std::pow(f1, i1) == std::pow(double(f1), double(i1)) );
+  check_ret_type<double>(std::pow(d1, i1));
+  check_ret_type<long double>(std::pow(ld1, i1));
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
Index: testsuite/tr1/8_c_compatibility/cmath/overloads.cc
===================================================================
--- testsuite/tr1/8_c_compatibility/cmath/overloads.cc	(revision 135953)
+++ testsuite/tr1/8_c_compatibility/cmath/overloads.cc	(working copy)
@@ -206,9 +206,7 @@
   check_ret_type<long double>(std::tr1::pow(ld0, d0));
   check_ret_type<double>(std::tr1::pow(i0, i0));
   check_ret_type<double>(std::tr1::pow(d0, i0));
-  // DR 550.
-  // check_ret_type<double>(std::tr1::pow(f0, i0));
-  check_ret_type<float>(std::tr1::pow(f0, i0));
+  check_ret_type<double>(std::tr1::pow(f0, i0));
 
   check_ret_type<double>(std::tr1::remainder(d0, d0));
   check_ret_type<double>(std::tr1::remainder(d0, f0));

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]