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]

Re: [v3] std:: qualification in the include/std dir


Gabriel Dos Reis wrote:

The issue is more sensitive for std::valarray (but it does also apply
to std::complex).


The point is that the std::complex template is an example of algebraic
data structure built on top of its type parameter: The
functionalities it provides are constructed from those of the type
parameter. If you qualify the functionalities, then you suppress any
means by which user defined types could provide interfaces required to
make the whole thing work. std:: qualification defeats the Interface
Principle.


| Of course, I'm going to prepare the fix anyway: all the functions
| belonging to <cmath> must not be qualified, right?

Mostly yes. Notable exceptions are abs() applied to a complex<_Up>.

| Anything else?

No.

Thanks for your explanations. I have committed the below.

Paolo.

/////////
2003-07-07  Paolo Carlini  <pcarlini@unitus.it>

	* include/std/std_complex.h: Partially revert last
	changes: cmath functions must not be qualified.
diff -urN libstdc++-v3-orig/include/std/std_complex.h libstdc++-v3/include/std/std_complex.h
--- libstdc++-v3-orig/include/std/std_complex.h	2003-07-05 22:44:17.000000000 +0200
+++ libstdc++-v3/include/std/std_complex.h	2003-07-07 13:55:05.000000000 +0200
@@ -411,18 +411,18 @@
     {
       _Tp __x = __z.real();
       _Tp __y = __z.imag();
-      const _Tp __s = std::max(std::abs(__x), std::abs(__y));
+      const _Tp __s = std::max(abs(__x), abs(__y));
       if (__s == _Tp())  // well ...
         return __s;
       __x /= __s; 
       __y /= __s;
-      return __s * std::sqrt(__x * __x + __y * __y);
+      return __s * sqrt(__x * __x + __y * __y);
     }
 
   template<typename _Tp>
     inline _Tp
     arg(const complex<_Tp>& __z)
-    { return std::atan2(__z.imag(), __z.real()); }
+    { return atan2(__z.imag(), __z.real()); }
 
   // 26.2.7/5: norm(__z) returns the squared magintude of __z.
   //     As defined, norm() is -not- a norm is the common mathematical
@@ -462,7 +462,7 @@
   template<typename _Tp>
     inline complex<_Tp>
     polar(const _Tp& __rho, const _Tp& __theta)
-    { return complex<_Tp>(__rho * std::cos(__theta), __rho * std::sin(__theta)); }
+    { return complex<_Tp>(__rho * cos(__theta), __rho * sin(__theta)); }
 
   template<typename _Tp>
     inline complex<_Tp>
@@ -476,7 +476,7 @@
     {
       const _Tp __x = __z.real();
       const _Tp __y = __z.imag();
-      return complex<_Tp>(std::cos(__x) * std::cosh(__y), -std::sin(__x) * std::sinh(__y));
+      return complex<_Tp>(cos(__x) * cosh(__y), -sin(__x) * sinh(__y));
     }
 
   template<typename _Tp>
@@ -485,23 +485,23 @@
     {
       const _Tp __x = __z.real();
       const _Tp __y = __z.imag();
-      return complex<_Tp>(std::cosh(__x) * std::cos(__y), std::sinh(__x) * std::sin(__y));
+      return complex<_Tp>(cosh(__x) * cos(__y), sinh(__x) * sin(__y));
     }
 
   template<typename _Tp>
     inline complex<_Tp>
     exp(const complex<_Tp>& __z)
-    { return std::polar(std::exp(__z.real()), __z.imag()); }
+    { return std::polar(exp(__z.real()), __z.imag()); }
 
   template<typename _Tp>
     inline complex<_Tp>
     log(const complex<_Tp>& __z)
-    { return complex<_Tp>(std::log(std::abs(__z)), std::arg(__z)); }
+    { return complex<_Tp>(log(std::abs(__z)), std::arg(__z)); }
 
   template<typename _Tp>
     inline complex<_Tp>
     log10(const complex<_Tp>& __z)
-    { return std::log(__z) / std::log(_Tp(10.0)); }
+    { return std::log(__z) / log(_Tp(10.0)); }
 
   template<typename _Tp>
     inline complex<_Tp>
@@ -509,7 +509,7 @@
     {
       const _Tp __x = __z.real();
       const _Tp __y = __z.imag();
-      return complex<_Tp>(std::sin(__x) * std::cosh(__y), std::cos(__x) * std::sinh(__y)); 
+      return complex<_Tp>(sin(__x) * cosh(__y), cos(__x) * sinh(__y)); 
     }
 
   template<typename _Tp>
@@ -518,7 +518,7 @@
     {
       const _Tp __x = __z.real();
       const _Tp  __y = __z.imag();
-      return complex<_Tp>(std::sinh(__x) * std::cos(__y), std::cosh(__x) * std::sin(__y));
+      return complex<_Tp>(sinh(__x) * cos(__y), cosh(__x) * sin(__y));
     }
 
   template<typename _Tp>
@@ -530,16 +530,16 @@
 
       if (__x == _Tp())
         {
-          _Tp __t = std::sqrt(std::abs(__y) / 2);
+          _Tp __t = sqrt(abs(__y) / 2);
           return complex<_Tp>(__t, __y < _Tp() ? -__t : __t);
         }
       else
         {
-          _Tp __t = std::sqrt(2 * (std::abs(__z) + std::abs(__x)));
+          _Tp __t = sqrt(2 * (std::abs(__z) + abs(__x)));
           _Tp __u = __t / 2;
           return __x > _Tp()
             ? complex<_Tp>(__u, __y / __t)
-            : complex<_Tp>(std::abs(__y) / __t, __y < _Tp() ? -__u : __u);
+            : complex<_Tp>(abs(__y) / __t, __y < _Tp() ? -__u : __u);
         }
     }
 
@@ -569,17 +569,17 @@
     pow(const complex<_Tp>& __x, const _Tp& __y)
     {
       if (__x.imag() == _Tp())
-        return std::pow(__x.real(), __y);
+        return pow(__x.real(), __y);
 
-      complex<_Tp> __t = std::log(__x);
-      return std::polar(std::exp(__y * __t.real()), __y * __t.imag());
+      complex<_Tp> __t = log(__x);
+      return std::polar(exp(__y * __t.real()), __y * __t.imag());
     }
 
   template<typename _Tp>
     inline complex<_Tp>
     pow(const complex<_Tp>& __x, const complex<_Tp>& __y)
     {
-      return __x == _Tp() ? _Tp() : std::exp(__y * std::log(__x));
+      return __x == _Tp() ? _Tp() : exp(__y * log(__x));
     }
 
   template<typename _Tp>
@@ -588,7 +588,7 @@
     {
       return __x == _Tp()
         ? _Tp()
-        : std::polar(std::pow(__x, __y.real()), __y.imag() * std::log(__x));
+        : std::polar(pow(__x, __y.real()), __y.imag() * log(__x));
     }
 
   // 26.2.3  complex specializations

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