This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
libstdc++/10689: pow(std::complex(0),1/3) returns (nan, nan) instead of 0.
- From: Daniel dot Levine at jhuapl dot edu
- To: gcc-gnats at gcc dot gnu dot org
- Date: 8 May 2003 18:07:59 -0000
- Subject: libstdc++/10689: pow(std::complex(0),1/3) returns (nan, nan) instead of 0.
- Reply-to: Daniel dot Levine at jhuapl dot edu
>Number: 10689
>Category: libstdc++
>Synopsis: pow(std::complex(0),1/3) returns (nan, nan) instead of 0.
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Thu May 08 18:16:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator: Daniel Levine
>Release: gcc 3.2-7
>Organization:
>Environment:
Any.
>Description:
Executing the pow(0,y) function call for doubles correctly produces return values of 0 as long as y != 0. Doing the same with the pow(std::complex<double>(0),y) will return (nan, nan). This appears to be caused by the log(x) when x is 0 returning nan as it should. Further exp() will never return 0 so some check needs to be implemented so pow(std::complex<double>(0),y) can return 0 when y != 0.
This problem is not specific to complex<double>. Other complex floating point types would suffer from the same problem.
One final note, pow(std::complex<double>(0), 1) works because it triggers other code while pow(std::complex<double>(0), 1.0) fails.
>How-To-Repeat:
#include <iostream>
using namespace std;
complex<double> complexZero;
complex<double> cubeRootOf0 = pow(complexZero, 1.0/3.0);
cerr << cubeRootof0 << endl; // Should be 0.0;
complex<double> zeroToThe1.0 = pow(complexZero, 1.0);
cerr << zeroToThe1.0 << endl; // Should be 0.0;
complex<double> zeroToThe1 = pow(complexZero, 1);
cerr << zeroToThe1 << endl; // Is 0.0;
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: