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
math: Different results using x86 and x64 versions of Go 1 #3423
Labels
Comments
Owner changed to @nigeltao. |
The fundamental difference is demonstrated by this trivial program: func main() { x := 257.0 println(uint8(x)) } 6g: prints 1 8g: prints 0 iant tells me that gccgo prints 1 in 64-bit mode and 255 in 32-bit mode. I'll re-assign the bug to him, and let iant/rsc decide where to take it. phrozen10, a workaround is to change the lines in func HSVToRGB from r := uint8((fR * 255) + 0.5) g := uint8((fG * 255) + 0.5) b := uint8((fB * 255) + 0.5) to conv := func(x float64) uint8 { if x < 0 { return 0 } if x > 1 { return 255 } return uint8(int(x*255 + 0.5)) } r, g, b := conv(fR), conv(fG), conv(fB) That should give you similar colors on both 32-bit and 64-bit. Even so, the actual image produced will differ between the 32-bit and 64-bit versions. The sin/cos implementations are slightly different on each (IIUC 32-bit uses 80-bit floats for intermediate values, 64-bit uses 64-bit floats throughout), and even though the differences are initially small, chaotic attractors will magnify any small perturbation. Owner changed to @ianlancetaylor. |
Thank you Nigel. I'll make the necessary modifications you stated and test over 64-bit. About the sin and cos implementations, I'll check if there are any differences, though I add random noise to the attractor coordinates from (-0.0025, 0.0025) on each iteration, so I don't think the small deviation would differ a lot from that. I may have to take out the blur to check for differences. They are chaotic after all. I'll keep checking here for any updates on the issue. Thank you again for your insight. |
I don't believe there's anything to fix here, sadly. In all non-constant conversions involving floating-point or complex values, if the result type cannot represent the value the conversion succeeds but the result value is implementation-dependent. - http://golang.org/ref/spec#Conversions You can't convert 257.0 to a byte and expect a specific answer. Status changed to Unfortunate. |
In all non-constant conversions involving floating-point or complex values, if the result type cannot represent the value the conversion succeeds but the result value is implementation-dependent. - http://golang.org/ref/spec#Conversions At least make sure that official go implementations handle it the same way? :S |
Usually the reason a spec says something is implementation-dependent is because the easiest/most natural/most efficient choices depends on details of the surrounding implementation. If we didn't want that flexibility and were willing to make the implementations all agree, we wouldn't say it was implementation-dependent. |
Issue #3966 has been merged into this issue. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
by phrozen10:
Attachments:
The text was updated successfully, but these errors were encountered: