Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260731043101.GM27423@brightrain.aerifal.cx>
Date: Fri, 31 Jul 2026 00:31:02 -0400
From: Rich Felker <dalias@...c.org>
To: Damian McGuckin <damianm@....com.au>
Cc: musl@...ts.openwall.com, Paul Zimmermann <Paul.Zimmermann@...ia.fr>
Subject: Re: issue in acosh

On Fri, Jul 31, 2026 at 12:11:10AM -0400, Rich Felker wrote:
> On Fri, Jul 31, 2026 at 11:08:39AM +1000, Damian McGuckin wrote:
> > On Thu, 30 Jul 2026, Rich Felker wrote:
> > 
> > > >         if (einf <= e || e < b ) /* x < 0 || x is a NaN || x == INF || x < 1 */
> > > >         {
> > > >             return x != x || x == INFINITY ? x + x : (x - x) / (x - x);
> > > >         }
> > > 
> > > I don't think nan/inf need special treatment here. Just
> > > 
> > > 	if (e < 0x3ff) x = 0;
> > > 
> > > should make it work fine.
> > 
> > I do not quite understand.
> > 
> > Also, you need to treat -INFINITY different to +INFINITY.
> 
> The comment is already correct for -inf and +inf. You pass a negative
> value to log() and get nan. You pass a +inf to log and get +inf.
> 
> The only case which is not already handled seems to be some numerical
> instability around particular values. I need to (or someone needs to)
> trace what happens when the failing argument is passed in, but
> replacing any finite value <1 with 0 (my code above for that wasn't
> quite right) should work to get the desired nan.

The problem looks to be that, when x is negative,

    2*x - 1/(x+sqrt(x*x-1))

is a very inaccurate way of computing the desired value

    x + sqrt(x*x-1)

I'm not even clear why the former form is preferred for
medium-magnitude positive x; it doesn't seem to be avoiding any
overflow or cancellation problems. But it's especially bad when
x+sqrt(x*x-1) has cancellation and hardly any bits of precision in the
result, which is what occurs when x is negative.

So either we need to special-case negative x and replace it with 0, or
avoid the above form.

Rich

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.