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: tan function returns different results depending on platform #18354
Comments
Personally I don't think we should promise that all floating point math operations will return exactly the same result on all platforms. See #17895. However, you are asking a slightly different question: should we promise that the math functions will return the same result for the same arguments on all platforms? If we want to make that promise, we will have to give up the assembly implementations of most math functions. So again I'm inclined to say that we should not make that promise. People who need identical results on all platforms must take other approaches--for example, copy the pure Go implementation from the math package. I note that in C, running on amd64, I get the results that you get on PPC. |
That's what I guessed the answer would be, so we don't give up performance for most users. In any case, we should document it probably, at least in the package doc. |
I think the question is rather, should we make various pure Go
math functions correctly rounded to <1ulp.
See also #9546 and the issues referenced.
|
I added a note to the top level math documentation that the result might not be the same on different architectures. As a guidance, is it ok to state it only there, or should I add this to the individual methods? |
Personally I think the package documentation is sufficient. The language itself does not guarantee that the results of floating point operations will be the same on all architectures. See #17895 . |
CL https://golang.org/cl/34938 mentions this issue. |
Updates #18354. Change-Id: I76bc4a73d8dc99eeda14b395e451d75a65184191 Reviewed-on: https://go-review.googlesource.com/45013 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Rob Pike <r@golang.org>
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?OS X:
go version go1.6 darwin/amd64
PowerPC (PPC):
go version go1.4.2 gccgo (GCC) 5.4.0 linux/ppc64le
s390x:
go version go1.4.2 gccgo (GCC) 5.4.0 linux/s390x
What operating system and processor architecture are you using (
go env
)?OS X:
PPC:
s390x:
What did you do?
Ran this program:
Play at https://play.golang.org/p/vfEPHNlzIo
What did you expect to see?
What did you see instead?
On OS X, worked as expected but on PPC and s390x, saw this instead:
Note the difference in the result of
tan(20)
.Browsing through the source, it appears to be a difference between the pure-Go implementation and various assembly implementations for the
tan
function.I believe PPC & s390 use the pure-Go implementation while my OS X box uses assembly (as does any arm, amd64, 386 box).
Here's the diff for the
0 <= n <= 100
:Is this expected/accepted behavior?
The text was updated successfully, but these errors were encountered: