ANSI-C99 7.3.8.3.3 says that the real part of the result csqrt() cannot be negative. However, when the argument's real part is zero and the imag part is negative, such as csqrt(0.0-1.0*I), it returns a negative real. Looking at the s_csqrt.c (and s_csqrtf.c and s_csqrtl.c) ---------- s_csqrt.c near line 78 ---------- else if (rcls == FP_ZERO) { double r = __ieee754_sqrt (0.5 * fabs (__imag__ x)); >>> __real__ res = __copysign (r, __imag__ x); >>> __imag__ res = r; } --------------------------------------------- The two lines marked with >>> appear to be the problem. When the real part of the argument is zero, then the real part of the result should be positive and the imag part of the result should have the same sign as the imag part of the argument, and both parts of the result should have the same magnitude. In other words... ---------- suggested s_csqrt.c near line 78 ---------- else if (rcls == FP_ZERO) { double r = __ieee754_sqrt (0.5 * fabs (__imag__ x)); >>> __real__ res = r; >>> __imag__ res = __copysign (r, __imag__ x); } --------------------------------------------- Please test this of course, but I believe this will solve the problem. Once this is fixed, all the other functions that depend on csqrt() should be tested. For example, the recently patched cacosh()(bug#2153) will need to be fixed again. -Wes Loewer
*** This bug has been marked as a duplicate of 1466 ***