[PATCH v2 20/25] math: Use atanf from CORE-MATH

Paul Zimmermann Paul.Zimmermann@inria.fr
Tue Dec 10 08:47:24 GMT 2024


       Hi DJ,

> One question about the tail and of sysdeps/ieee754/flt-32/s_atanf.c wrt copysign

let me answer that question

> > +  /* now |x| >= 1 */
> > +  r = copysign (0x1.0fdaa22168c23p-7, z) - r + copysign (0x1.9p0, z);
> 
> This seems odd; there's no reason to have two copysign's - they could be
> combines into "copysign(...) - r".  Unless there's rounding issues, in
> which case, a comment and parens are warranted to force operation order
> despite optimizations.

here r approximates atan(1/x), and we use atan(x) + atan(1/x) = sign(x)*pi/2.

Let H=0x1.9p0 and L=0x1.0fdaa22168c23p-7, where H+L approximates pi/2.

If you write sign(z)*L + (-r + sign(z)*H), it fails for x=0x1.98c252p+12 and
rounding upward.

If you write sign(z)*PI - r, where PI is a double approximation of pi to
nearest, it fails for x=0x1.ddf9f6p+0 and rounding upward.

Thus indeed we have to write (sign(z)*L + -r) + sign(z)*H, unless you find a
more clever way. I'll add comments upstream.

Paul


More information about the Libc-alpha mailing list