-
Notifications
You must be signed in to change notification settings - Fork 18k
math: portable FMA implementation incorrectly returns +0 when x*y ~ 0, x*y < 0 and z = 0 #73757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Adding zero usually does not change the original value. However, there is an exception with negative zero. (e.g. (-0) + (+0) = (+0)) This applies when x * y is negative and underflows. Fixes golang#73757
Change https://go.dev/cl/673856 mentions this issue: |
I think the fix you proposed is only correct if |
That case will be handled in these lines: Lines 98 to 101 in 6885cc0
Therefore, Lines 102 to 108 in 6885cc0
|
Ah, ok. I guess the only way to get |
There's arguably a second bug here: the compiler should treat |
Go version
go version go1.24.3 linux/amd64
Output of
go env
in your module/workspace:What did you do?
https://go.dev/play/p/DgFhrLf1CuF
What did you see happen?
What did you expect to see?
The exact result of the calculation is
0x1p-1022 * (-0x1p-1022) + 0 = -0x1p-2044
. Since-0x1p-2044
cannot be represented in float64, it underflows and the result becomes-0
.The text was updated successfully, but these errors were encountered: