Skip to content

Commit 3e57644

Browse files
committed
fix atan2 setting errno on Solaris when both arguments are +-0
1 parent 14a5ad1 commit 3e57644

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Modules/cmathmodule.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -926,10 +926,19 @@ cmath_phase_impl(PyObject *module, Py_complex z)
926926

927927
errno = 0;
928928
phi = atan2(z.imag, z.real); /* should not cause any exception */
929-
if (errno != 0)
929+
if (errno != 0) {
930+
#if defined(__sun)
931+
/* On Solaris, atan2 incorrectly sets errno when both arguments are
932+
zero. The result is correct though, so we can safely ignore the
933+
errno and return it. */
934+
if ((z.imag == 0.0 || z.imag == -0.0) && (z.real == 0.0 || z.real == -0.0)) {
935+
return PyFloat_FromDouble(phi);
936+
}
937+
#endif
930938
return math_error();
931-
else
939+
} else {
932940
return PyFloat_FromDouble(phi);
941+
}
933942
}
934943

935944
/*[clinic input]

0 commit comments

Comments
 (0)