Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260803164112.GJ3520958@port70.net>
Date: Mon, 3 Aug 2026 18:41:12 +0200
From: Szabolcs Nagy <nsz@...t70.net>
To: Rich Felker <dalias@...c.org>
Cc: musl@...ts.openwall.com
Subject: Re: fix acosh for x<0

* Rich Felker <dalias@...c.org> [2026-08-03 12:00:25 -0400]:
> On Mon, Aug 03, 2026 at 02:10:37PM +0200, Szabolcs Nagy wrote:
> > >From 84bf2a51418196f96192d7fc8f11cf268b02e1b1 Mon Sep 17 00:00:00 2001
> > From: Szabolcs Nagy <nsz@...t70.net>
> > Date: Mon, 3 Aug 2026 06:41:28 +0000
> > Subject: [PATCH 1/2] math: fix acosh for x<0
> > 
> > acosh(-0x1.8p15) returned -3.7534177368329567 instead of nan.
> > 
> > the same issue got fixed for acoshf and acoshl in commits
> > c4c38e6364323b6d83ba3428464e19987b981d7a and
> > 6d10102709df4bc966d2846c1c45cd667e5048e5 here we follow the latter.
> > 
> > reported by Paul Zimmermann.
> > ---
> >  src/math/acosh.c | 13 +++++++------
> >  1 file changed, 7 insertions(+), 6 deletions(-)
> > 
> > diff --git a/src/math/acosh.c b/src/math/acosh.c
> > index badbf908..75ce95aa 100644
> > --- a/src/math/acosh.c
> > +++ b/src/math/acosh.c
> > @@ -9,16 +9,17 @@
> >  double acosh(double x)
> >  {
> >  	union {double f; uint64_t i;} u = {.f = x};
> > -	unsigned e = u.i >> 52 & 0x7ff;
> > -
> > -	/* x < 1 domain error is handled in the called functions */
> > +	unsigned e = u.i >> 52;
> >  
> >  	if (e < 0x3ff + 1)
> > -		/* |x| < 2, up to 2ulp error in [1,1.125] */
> > +		/* 0 <= x < 2, up to 2ulp error in [1,1.125] */
> >  		return log1p(x-1 + sqrt((x-1)*(x-1)+2*(x-1)));
> >  	if (e < 0x3ff + 26)
> > -		/* |x| < 0x1p26 */
> > +		/* 2 <= x < 0x1p26 */
> >  		return log(2*x - 1/(x+sqrt(x*x-1)));
> > -	/* |x| >= 0x1p26 or nan */
> > +	if (e & 0x800)
> > +		/* x < 0 or x = -0, invalid */
> > +		return (x-x)/(x-x);
> > +	/* x >= 0x1p26 or nan */
> >  	return log(x) + 0.693147180559945309417232121458176568;
> >  }
> 
> I don't think you need the special case for negative. The final case
> of passing a negative x to log will already produce a nan.

unfortunately it is needed for -0
log(-0)=-inf instead of nan

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.