-
Notifications
You must be signed in to change notification settings - Fork 18k
math: discrepancy in Atan2 special case #35446
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
This causes |
In general the |
I'm happy to add the |
Change https://golang.org/cl/220689 mentions this issue: |
Change https://golang.org/cl/223420 mentions this issue: |
Note that there are tests already in place to handle this special case correctly. https://github.com/golang/go/blob/master/src/math/all_test.go#L848-L866
But the s390x assembly just has a special case specifically to pass the (-Pi, +Inf) test case. https://github.com/golang/go/blob/master/src/math/atan2_s390x.s#L137
Note, that the comment is not correct with respect to the behavior, it actually returns |
Does this issue reproduce with the latest release?
yes
The special cases for
Atan2
areAtan2(y, +Inf) = 0
is handled differently between the pure go code and the s390x implementation.The pure go implementation actually conforms to C99 Annex F. 9.1.4 which specifies:
atan2(±y,+∞) returns ± 0 for finite y>0.
Specifically, the sign of zero depends on the sign of y, while the s390x implementation returns +0 for all values of y.
Note that this behavior affects special case handling of
math/cmplx
as well since those functions rely onmath
for the underlying implementations.A decision should be made on what the specification should state for the sign of zero in this case. I am not sure if updating the go specification to depend on the sign of y (C99) would be incompatible with the go compatibility promise since the current specification doesn't explicitly state that the sign should be positive. It seems that the majority implementation is already conforming to the C99 specification in any case.
The text was updated successfully, but these errors were encountered: