git: 93fc67896550 - main - Fix incorrect powf(3) result with x near 1 and |y| much larger than 1

Dimitry Andric dim at FreeBSD.org
Mon Feb 8 22:34:22 UTC 2021


On 8 Feb 2021, at 23:09, Alexander Richardson <arichardson at freebsd.org> wrote:
> 
> On Mon, 8 Feb 2021, 19:49 Dimitry Andric, <dim at freebsd.org> wrote:
> The branch main has been updated by dim:
> 
> URL: https://cgit.FreeBSD.org/src/commit/?id=93fc67896550548f91b307dbe3053f11db5d4a8a
> 
> commit 93fc67896550548f91b307dbe3053f11db5d4a8a
> Author:     Steve Kargl <sgk at troutmask.apl.washington.edu>
> AuthorDate: 2021-02-08 19:45:30 +0000
> Commit:     Dimitry Andric <dim at FreeBSD.org>
> CommitDate: 2021-02-08 19:48:43 +0000
> 
>     Fix incorrect powf(3) result with x near 1 and |y| much larger than 1
> 
>     This adjusts the check to trigger overflow/underflow to a slightly lower
>     value.
> 
>     Before: powf(9.999995e-01, -1.342177e+08) -> inf
>     After:  powf(9.999995e-01, -1.342177e+08) -> 1.858724e+31
> 
>     MFC after:      1 week
> ---
>  lib/msun/src/e_powf.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/msun/src/e_powf.c b/lib/msun/src/e_powf.c
> index 53f1d37d6bec..33eedad50b16 100644
> --- a/lib/msun/src/e_powf.c
> +++ b/lib/msun/src/e_powf.c
> @@ -136,7 +136,7 @@ __ieee754_powf(float x, float y)
>      /* |y| is huge */
>         if(iy>0x4d000000) { /* if |y| > 2**27 */
>         /* over/underflow if x is not close to one */
> -           if(ix<0x3f7ffff8) return (hy<0)? sn*huge*huge:sn*tiny*tiny;
> +           if(ix<0x3f7ffff7) return (hy<0)? sn*huge*huge:sn*tiny*tiny;
>             if(ix>0x3f800007) return (hy>0)? sn*huge*huge:sn*tiny*tiny;
>         /* now |1-x| is tiny <= 2**-20, suffice to compute
>            log(x) by x-x^2/2+x^3/3-x^4/4 */
> 
> 
> Do we have a test with previously buggy values? If not it would be good to add one.

Nope, I'll see if I can grok the awful kyua stuff enough to add it.

-Dimitry

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 223 bytes
Desc: Message signed with OpenPGP
URL: <http://lists.freebsd.org/pipermail/dev-commits-src-main/attachments/20210208/09f5dec0/attachment.sig>


More information about the dev-commits-src-main mailing list