This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug libc/2181] New: csqrt() sometimes returns negative real
- From: "wjltemp-temp01 at yahoo dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sources dot redhat dot com
- Date: 19 Jan 2006 17:37:21 -0000
- Subject: [Bug libc/2181] New: csqrt() sometimes returns negative real
- Reply-to: sourceware-bugzilla at sourceware dot org
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
--
Summary: csqrt() sometimes returns negative real
Product: glibc
Version: unspecified
Status: NEW
Severity: normal
Priority: P2
Component: libc
AssignedTo: aj at suse dot de
ReportedBy: wjltemp-temp01 at yahoo dot com
CC: glibc-bugs at sources dot redhat dot com
http://sourceware.org/bugzilla/show_bug.cgi?id=2181
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.