diff options
author | Gabriel Dos Reis <gdr@integrable-solutions.net> | 2003-05-20 06:52:11 +0000 |
---|---|---|
committer | Gabriel Dos Reis <gdr@gcc.gnu.org> | 2003-05-20 06:52:11 +0000 |
commit | 1db0418ae570eff510bb0c52cb5dbed54320d5a4 (patch) | |
tree | ea744e6750ac1694c4136ebf05f2ad62dad71e22 | |
parent | 29ad6d3f115bd906b1611092453ab48a4653d0c9 (diff) | |
download | gcc-1db0418ae570eff510bb0c52cb5dbed54320d5a4.zip gcc-1db0418ae570eff510bb0c52cb5dbed54320d5a4.tar.gz gcc-1db0418ae570eff510bb0c52cb5dbed54320d5a4.tar.bz2 |
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
-rw-r--r-- | libstdc++-v3/ChangeLog | 5 | ||||
-rw-r--r-- | libstdc++-v3/include/std/std_complex.h | 14 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/26_numerics/complex/pow.C | 14 |
3 files changed, 29 insertions, 4 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 6fc5fe7..6f3c110 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,8 @@ +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 diff --git a/libstdc++-v3/include/std/std_complex.h b/libstdc++-v3/include/std/std_complex.h index 87e4bcb..e943f5e 100644 --- a/libstdc++-v3/include/std/std_complex.h +++ b/libstdc++-v3/include/std/std_complex.h @@ -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 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 0000000..c3f8479 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/complex/pow.C @@ -0,0 +1,14 @@ +// 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; +} |