Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 12 Jun 2024 18:58:03 +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-OTJq6aSnQQ@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 #11 from Steve Kargl <kargl@FreeBSD.org> ---
Someone smarter than me may need to look at this!  With the original
src/s_fma.c, I see

dble (x,y,z): -0x1p+0  0x1p+0  0x1p+0
mpfr (x,y,z): -0x1p+0  0x1p+0  0x1p+0
        mpfr    libm
RNDN:  0x0p+0  0x0p+0
RNDU:  0x0p+0  0x0p+0
RNDD: -0x0p+0 -0x0p+0
RNDZ:  0x0p+0  0x0p+0

dble (x,y,z):  0x1p+0 -0x1p+0  0x1p+0
mpfr (x,y,z):  0x1p+0 -0x1p+0  0x1p+0
        mpfr    libm
RNDN:  0x0p+0  0x0p+0
RNDU:  0x0p+0  0x0p+0
RNDD: -0x0p+0 -0x0p+0
RNDZ:  0x0p+0  0x0p+0

dble (x,y,z): -0x1p+0 -0x1p+0 -0x1p+0
mpfr (x,y,z): -0x1p+0 -0x1p+0 -0x1p+0
        mpfr    libm
RNDN:  0x0p+0  0x0p+0
RNDU:  0x0p+0  0x0p+0
RNDD: -0x0p+0 -0x0p+0
RNDZ:  0x0p+0  0x0p+0

dble (x,y,z):  0x1.ffffffffffff8p-501  0x1.0000000000004p-500 -0x1p-1000
mpfr (x,y,z):  0xf.fffffffffffcp-504  0x1.0000000000004p-500 -0x1p-1000
        mpfr    libm
RNDN: -0x0p+0  0x0p+0
RNDU: -0x0p+0  0x0p+0
RNDD: -0x1p-1074 -0x1p-1074
RNDZ: -0x0p+0  0x0p+0

The first groups of three are fma(-1.,1.,1.), fma(1.,-1.,1.), and
fma(-1.,-1.,-1.) with the four rounding modes.  The group is Victor's examp=
le
where the rounding is wrong.

If one looks in src/s_fma.c, there is a special case for addends that sum to
zero.
This is the 'if (r.hi =3D=3D 0.0) {}' block of code (lines 263-274).  If I =
comment=20
out this block, I get wrong results for fma(-1.,1.,1.), fma(1.,-1.,1.), and
fma(-1.,-1.,-1.), but correct results for Victor's input. :(

dble (x,y,z): -0x1p+0  0x1p+0  0x1p+0
mpfr (x,y,z): -0x1p+0  0x1p+0  0x1p+0
        mpfr    libm
RNDN:  0x0p+0  0x0p+0
RNDU:  0x0p+0  0x0p+0
RNDD: -0x0p+0  0x0p+0
RNDZ:  0x0p+0  0x0p+0

dble (x,y,z):  0x1p+0 -0x1p+0  0x1p+0
mpfr (x,y,z):  0x1p+0 -0x1p+0  0x1p+0
        mpfr    libm
RNDN:  0x0p+0  0x0p+0
RNDU:  0x0p+0  0x0p+0
RNDD: -0x0p+0  0x0p+0
RNDZ:  0x0p+0  0x0p+0

dble (x,y,z): -0x1p+0 -0x1p+0 -0x1p+0
mpfr (x,y,z): -0x1p+0 -0x1p+0 -0x1p+0
        mpfr    libm
RNDN:  0x0p+0  0x0p+0
RNDU:  0x0p+0  0x0p+0
RNDD: -0x0p+0  0x0p+0
RNDZ:  0x0p+0  0x0p+0

dble (x,y,z):  0x1.ffffffffffff8p-501  0x1.0000000000004p-500 -0x1p-1000
mpfr (x,y,z):  0xf.fffffffffffcp-504  0x1.0000000000004p-500 -0x1p-1000
        mpfr    libm
RNDN: -0x0p+0 -0x0p+0
RNDU: -0x0p+0 -0x0p+0
RNDD: -0x1p-1074 -0x1p-1074
RNDZ: -0x0p+0 -0x0p+0

--=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-OTJq6aSnQQ>