Commit 1db0418a by Gabriel Dos Reis Committed by Gabriel Dos Reis

re PR libstdc++/10689 (pow(std::complex(0),1/3) returns (nan, nan) instead of 0.)

	PR libstdc++/10689
	* include/std/std_complex.h (pow): Tidy

From-SVN: r66989
parent 29ad6d3f
2003-05-20 Gabriel Dos Reis <gdr@integrable-solutions.net>
PR libstdc++/10689
* include/std/std_complex.h (pow): Tidy.
2003-05-19 Paolo Carlini <pcarlini@unitus.it>
* testsuite/27_io/basic_filebuf/close/char/4.cc: New file, testing
......
......@@ -565,24 +565,30 @@ namespace std
}
template<typename _Tp>
inline complex<_Tp>
complex<_Tp>
pow(const complex<_Tp>& __x, const _Tp& __y)
{
return exp(__y * log(__x));
if (__x.imag() == _Tp())
return pow(__x.real(), __y);
complex<_Tp> __t = log(__x);
return polar(exp(__y * __t.real()), __y * __t.imag());
}
template<typename _Tp>
inline complex<_Tp>
pow(const complex<_Tp>& __x, const complex<_Tp>& __y)
{
return exp(__y * log(__x));
return __x == _Tp() ? _Tp() : exp(__y * log(__x));
}
template<typename _Tp>
inline complex<_Tp>
pow(const _Tp& __x, const complex<_Tp>& __y)
{
return exp(__y * log(__x));
return __x == _Tp()
? _Tp()
: polar(pow(__x, __y.real()), __y.imag() * log(__x));
}
// 26.2.3 complex specializations
......
// PR libbstdc++/10689
// Origin: Daniel.Levine@jhuaph.edu
#include <complex>
#include <testsuite_hooks.h>
int main()
{
std::complex<double> z(0, 1) ;
VERIFY(pow(z, 1.0/3.0) == 0.0);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment