-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
cmd/compile: unstable arithmetic #52293
Comments
This is expected, at least according to the current spec. See https://go.dev/ref/spec#Arithmetic_operators , look for "fused multiply and add". We do use FMA on ARM64 (and some other architectures). |
Thanks! That's indeed good to know. But if I understand the behavior correctly, and it is all about FMA. Shouldn't we at least have consistent results for each of the return statements on a specific architecture? Meaning for all compute functions:
they at least all produce the same results (does not necessarily require linux/amd64 == darwin/arm64)? |
The + and - are the difference. They are not the same order of operation, e.g. If it really matters, you can try adding explicit rounding, e.g. |
Isn't compute1 and compute3 exactly the same in its arthmetic order? They are still result in a I can't certainly answer regarding the influences yet without enough in-depth practice. But as far as I could imagine, it might influence the numeric stability of different solvers and convey hidden issues, which eventually cause unexpected results on different platforms (e.g., Laplacian and Poisson solvers that compute differently optimized geometric structures where one is a good geometry and the other is a faulty geometry). |
The compiler is permitted but not required to use FMA for any given expression. People who need precise control over floating-point operations can and should use conversions to |
Thanks for the suggestions! I will close this for now and need further develop some expertise here and see how to tacle this precisely. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://go.dev/play/p/5zmfDpA4ylc
What did you expect to see?
This result is what go.dev/play produces
What did you see instead?
This is the result produced on a M1 mac.
The text was updated successfully, but these errors were encountered: