public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/2153] New: cacosh() not ANSI-C99 complient
@ 2006-01-14 15:02 wjltemp-temp01 at yahoo dot com
  2006-01-15 15:43 ` [Bug libc/2153] " aj at suse dot de
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: wjltemp-temp01 at yahoo dot com @ 2006-01-14 15:02 UTC (permalink / raw)
  To: glibc-bugs

glibc-2.3.6

The cacosh() function does not always give correct ANSI-C99 complient results. 
When the real part of the argument is negative, the result is the negative of
what it should be.

For example, the result of cacosh(-0.3 + 0.4*I) should be 0.405112 + 1.851426*I,
but instead, the result comes out -0.405112 + -1.851426*I.  

While this is one of the many inverse hyperbolic cosines, it's not THE inverse
hyperbolic cosine specified by ANSI-C99 7.3.6.1.3, which states that the real
part of the result must be non-negative.  ("The cacosh functions return the
complex arc hyperbolic cosine value, in the range of a half-strip of
non-negative values along the real axis and in the interval [-i*pi, +i*pi] along
the imaginary axis.")

This can be easily fixed by adding either of the following in s_cacosh.c (and
related s_cacoshf.c and s_cacoshl.c):

--------- original s_cacosh.c, line 67 ----------
  else
    {
      __complex__ double y;

      __real__ y = (__real__ x - __imag__ x) * (__real__ x + __imag__ x) - 1.0;
      __imag__ y = 2.0 * __real__ x * __imag__ x;

      y = __csqrt (y);

      __real__ y += __real__ x;
      __imag__ y += __imag__ x;

      res = __clog (y);
    }

--------- proposed s_cacosh.c ----------
  else
    {
      __complex__ double y;

      __real__ y = (__real__ x - __imag__ x) * (__real__ x + __imag__ x) - 1.0;
      __imag__ y = 2.0 * __real__ x * __imag__ x;

      y = __csqrt (y);

>>>   if (__real__ x < 0.0)
>>>     y = -y;

      __real__ y += __real__ x;
      __imag__ y += __imag__ x;

      res = __clog (y);
    }

--------- or another proposed s_cacosh.c ----------
  else
    {
      __complex__ double y;

      __real__ y = (__real__ x - __imag__ x) * (__real__ x + __imag__ x) - 1.0;
      __imag__ y = 2.0 * __real__ x * __imag__ x;

      y = __csqrt (y);

      __real__ y += __real__ x;
      __imag__ y += __imag__ x;

      res = __clog (y);

>>>   if (__real__ x < 0.0)
>>>     res = -res;
    }

-----------------------------------------

Thank you,
-Wes Loewer

-- 
           Summary: cacosh() not ANSI-C99 complient
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper at redhat dot com
        ReportedBy: wjltemp-temp01 at yahoo dot com
                CC: glibc-bugs at sources dot redhat dot com


http://sourceware.org/bugzilla/show_bug.cgi?id=2153

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-01-19 18:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-14 15:02 [Bug libc/2153] New: cacosh() not ANSI-C99 complient wjltemp-temp01 at yahoo dot com
2006-01-15 15:43 ` [Bug libc/2153] " aj at suse dot de
2006-01-15 17:51 ` cvs-commit at gcc dot gnu dot org
2006-01-15 17:51 ` aj at suse dot de
2006-01-19 18:33 ` wjltemp-temp01 at yahoo dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).