https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117216
Bug ID: 117216
Summary: wrong sign for complex sqrt(-x-i0) (for targets
without C99 math)
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: vincenzo.innocente at cern dot ch
Target Milestone: ---
in
https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/std/complex#L1183
one should test "std::signbit(__y") not "__y<_Tp()"
I discovered this testing on AMD GPU using hipcc
It can be reproduced with gcc on Linux adding -D_GLIBCXX_USE_C99_COMPLEX=0 on
the command line
cat sqrt.cpp
#include<complex>
#include<iostream>
int main() {
std::complex<double> z = {-4.0,-0.0};
std::cout << z << ' ' << std::sqrt(z) << std::endl;
std::cout << std::hypot(z.real(),z.imag()) << ' ' <<
std::atan2(z.imag(),z.real()) << std::endl;
std::cout << z.imag() << (z.imag() < 0 ? " negative" : " positive") <<
std::endl;
std::cout << z.imag() << ( std::signbit(z.imag()) ? " negative" : "
positive") << std::endl;
std::cout <<
std::polar(std::sqrt(std::hypot(z.real(),z.imag())),0.5*std::atan2(z.imag(),z.real()))
<< std::endl;
return 0;
}
innocent@vinmacscreen binary64 % c++ -O3 -march=native sqrt.cpp; ./a.out
(-4,-0) (0,-2)
4 -3.14159
-0 positive
-0 negative
(1.22465e-16,-2)
innocent@vinmacscreen binary64 % c++ -O3 -march=native sqrt.cpp
-D_GLIBCXX_USE_C99_COMPLEX=0
innocent@vinmacscreen binary64 % c++ -O3 -march=native sqrt.cpp; ./a.out
(-4,-0) (0,-2)
4 -3.14159
-0 positive
-0 negative
(1.22465e-16,-2)