From ab6501eff3b9e1638296bfae030377b9f358b077 Mon Sep 17 00:00:00 2001 From: gdr Date: Tue, 20 May 2003 06:52:11 +0000 Subject: [PATCH 1/1] PR libstdc++/10689 * include/std/std_complex.h (pow): Tidy git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@66989 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/ChangeLog | 5 +++++ libstdc++-v3/include/std/std_complex.h | 14 ++++++++++---- libstdc++-v3/testsuite/26_numerics/complex/pow.C | 14 ++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 libstdc++-v3/testsuite/26_numerics/complex/pow.C diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 6fc5fe7205c..6f3c11083b0 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,8 @@ +2003-05-20 Gabriel Dos Reis + + PR libstdc++/10689 + * include/std/std_complex.h (pow): Tidy. + 2003-05-19 Paolo Carlini * testsuite/27_io/basic_filebuf/close/char/4.cc: New file, testing diff --git a/libstdc++-v3/include/std/std_complex.h b/libstdc++-v3/include/std/std_complex.h index 87e4bcb4d26..e943f5edcee 100644 --- a/libstdc++-v3/include/std/std_complex.h +++ b/libstdc++-v3/include/std/std_complex.h @@ -565,24 +565,30 @@ namespace std } template - 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 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 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 diff --git a/libstdc++-v3/testsuite/26_numerics/complex/pow.C b/libstdc++-v3/testsuite/26_numerics/complex/pow.C new file mode 100644 index 00000000000..c3f8479828d --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/complex/pow.C @@ -0,0 +1,14 @@ +// PR libbstdc++/10689 +// Origin: Daniel.Levine@jhuaph.edu + +#include +#include + +int main() +{ + std::complex z(0, 1) ; + + VERIFY(pow(z, 1.0/3.0) == 0.0); + + return 0; +} -- 2.11.0