-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Description
$ go version go version go1.13.4 linux/amd64
Does this issue reproduce with the latest release?
yes
The special cases for Atan2 are
// Special cases are (in order):
// Atan2(y, NaN) = NaN
// Atan2(NaN, x) = NaN
// Atan2(+0, x>=0) = +0
// Atan2(-0, x>=0) = -0
// Atan2(+0, x<=-0) = +Pi
// Atan2(-0, x<=-0) = -Pi
// Atan2(y>0, 0) = +Pi/2
// Atan2(y<0, 0) = -Pi/2
// Atan2(+Inf, +Inf) = +Pi/4
// Atan2(-Inf, +Inf) = -Pi/4
// Atan2(+Inf, -Inf) = 3Pi/4
// Atan2(-Inf, -Inf) = -3Pi/4
// Atan2(y, +Inf) = 0
// Atan2(y>0, -Inf) = +Pi
// Atan2(y<0, -Inf) = -Pi
// Atan2(+Inf, x) = +Pi/2
// Atan2(-Inf, x) = -Pi/2
Atan2(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 on math 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.