This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Fix ctan, ctanh overflow (bug 11521)


On 04/09/2012 05:46 PM, Joseph S. Myers wrote:
Bug 11521 reports a problem with ctanh returning incorrect results in
cases where both numerator and denominator in the internal
calculations overflowed.

There are several related problems with both ctan and ctanh, only some
of which are addressed by the patch included in that bug.  The
calculations may overflow - but when they do, while one part of the
numerator is +/- 1, the other part may be subnormal, not zero; the
strategy used in the patch in the bug, of detecting overflow after the
fact, is unsuitable both for that reason and because it will raise
spurious overflow exceptions.  The internal calculations double one
part of the input before calling sincos, so resulting in an overflow
for arguments more than half of the maximum value.  And the
calculations of the denominator can suffer cancellation when one part
is zero or close to zero and the other part is close to an odd
multiple of pi/2.

I propose this patch, which uses the alternative formula used by the
patch in the bug report to address the problems of cancellation and
overflow from doubling the input - precisely the problems that formula
wasn't originally intended to address.  The overflow is addressed
using the same strategy as in cexp, splitting the exponent and using
two separate calls to exp if it's large enough for one call to
overflow.  Because the new formula avoids cancellation from cosh
(something close to 0) + cos (something close to an odd multiple of
pi), the case of denominator exactly 0, which might have arisen before
from cancellation, can no longer arise, so code to handle it is
removed.  Testcases are added for all the issues described, for both
ctan and ctanh.

Tested x86 and x86_64 and ulps updated accordingly.

This is fine, thanks!


Andreas
--
 Andreas Jaeger aj@{suse.com,opensuse.org} Twitter/Identica: jaegerandi
  SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
   GF: Jeff Hawn,Jennifer Guild,Felix Imendörffer,HRB16746 (AG Nürnberg)
    GPG fingerprint = 93A3 365E CE47 B889 DF7F  FED1 389A 563C C272 A126


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]