Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 16 Jun 2024 02:26:01 +0000
From:      bugzilla-noreply@freebsd.org
To:        bugs@FreeBSD.org
Subject:   [Bug 277783] libc fma() doesn't not return the correct zero sign
Message-ID:  <bug-277783-227-wy1kzHHqOc@https.bugs.freebsd.org/bugzilla/>
In-Reply-To: <bug-277783-227@https.bugs.freebsd.org/bugzilla/>
References:  <bug-277783-227@https.bugs.freebsd.org/bugzilla/>

next in thread | previous in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D277783

--- Comment #14 from Steve Kargl <kargl@FreeBSD.org> ---
Created attachment 251489
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=3D251489&action=
=3Dedit
New patch

The code for fma() and fmal() contain a special case when the addends sum to
zero, but it seems that it mishandles small low order bits especially if a
subnormal condition occurs.  One of the testcases in msun/tests (that I bro=
ke
with the original patch) is fma(-1.,1.,1.) with the intermediate results

(x,y,z): -0x1p+0  0x1p+0  0x1p+0
xy =3D {-0x1p-2, 0x0p+0}
r  =3D {0x0p+0, 0x0p+0}
spread =3D 2
zs =3D 0x1p-2

fma returns (xy.hi + zs +ldexp(xy.lo,spread)), which is fine.

For the case that Victor submitted one has

(x,y,z):  0x1.ffffffffffff8p-501  0x1.0000000000004p-500 -0x1p-1000
xy =3D {5.000000e-01, -3.944305e-31}
r  =3D {0.000000e+00 0.000000e+00}
spread =3D -999=20
zs =3D -5.000000e-01

For the original code, the special leads to
ldexp(xy.lo,spread)=3Dldexp(-3.944305e-31,-999), is not good.

The new patch skips the special case if xy.lo !=3D 0.  This then allows fma=
() to
call its add_and_denormalize() function.

--=20
You are receiving this mail because:
You are the assignee for the bug.=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-277783-227-wy1kzHHqOc>