[PATCH 11/15] math: Use atanpif from CORE-MATH
Paul Zimmermann
Paul.Zimmermann@inria.fr
Tue Feb 11 14:22:22 GMT 2025
> >> + if (__glibc_unlikely (e > 127 + 24))
> >> + {
> >> + float f = copysignf (0.5f, x);
> >> + if (__glibc_unlikely (e == 0xff))
> >> + {
> >> + if (t << 9)
> >> + return x + x; /* nan */
> >> + return f; /* inf */
> >> + }
> >> + /* Warning: 0x1.45f306p-2f / x underflows for |x| >= 0x1.45f306p+124 */
> >> + if (fabsf (x) >= 0x1.45f306p+124f)
> >> + return f - 4.0f / x;
> >
> > Are we just trying to get a reasonable denormal to subtract here, to get
> > the LSBs correct? It seems odd that you can just substitute a bigger
> > number and get valid results, unless it's a pre-calculated boundary
> > condition.
>
> Afaik it's a pre-calculated bondary from a glibc testcase [1].
>
> [1] https://gitlab.inria.fr/core-math/core-math/-/issues/36
>
> >
> >> + else
> >> + return f - 0x1.45f306p-2f / x;
> >> + }
it is to avoid a spurious underflow in 0x1.45f306p-2f / x.
In fact we can replace by any expression f - t where |t| < 1/2 ulp(0.5),
and t has the same sign than x, thus f - __builtin_copysignf(0x1p-26f,x)
should work (not tested).
Paul
More information about the Libc-alpha
mailing list