This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/13450] std::pow(std::complex<double>(-1.,0.),0.5) yields (NaN,0)
- From: "pkienzle at nist dot gov" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 12 Jan 2004 16:07:04 -0000
- Subject: [Bug libstdc++/13450] std::pow(std::complex<double>(-1.,0.),0.5) yields (NaN,0)
- References: <20031219173057.13450.pkienzle@nist.gov>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From pkienzle at nist dot gov 2004-01-12 16:06 -------
(In reply to comment #9)
> OK, I see what is going wrong. But the submitter's patch is not right
> either. To properly implement the branch cut, we need to test whether
> the imaginary part is a positive or negative zero (on IEEE-754
> plateform). Yes that is a crazy notion -- but we got it.
For example, the following is calculated by Matlab on IRIX:
>> (-1+realmin*1i)^0.5
0.0000 + 1.0000i
>> (-1-realmin*1i)^0.5
0.0000 - 1.0000i
> Therefore we need a primitive that tells the sign of a real number.
C99 has signbit and copysign. I was able to access them as follows:
#include <iostream>
#include <cmath>
int main(int argc, char *argv[])
{
double x=1.0, y=-1.0, z;
std::cout << "1.0/HUGE_VAL=" << x/HUGE_VAL << std::endl;
std::cout << "signbit(1.0/HUGE_VAL)="
<< __gnu_cxx::signbit(x/HUGE_VAL) << std::endl;
std::cout << "-1.0/HUGE_VAL=" << y/HUGE_VAL << std::endl;
std::cout << "signbit(-1.0/HUGE_VAL)="
<< __gnu_cxx::signbit(y/HUGE_VAL) << std::endl;
return 0;
}
[prog]$ ./a.out
1.0/HUGE_VAL=0
signbit(1.0/HUGE_VAL)=0
-1.0/HUGE_VAL=-0
signbit(-1.0/HUGE_VAL)=-2147483648
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13450