gh-122681: merge m_atan2() and c_atan2() helper functions (#122682) · sthagen/python-cpython@0b433aa · GitHub
Skip to content

Commit 0b433aa

Browse files
authored
pythongh-122681: merge m_atan2() and c_atan2() helper functions (python#122682)
1 parent 6ff82fd commit 0b433aa

3 files changed

Lines changed: 41 additions & 69 deletions

File tree

Modules/_math.h

Lines changed: 39 additions & 0 deletions

Modules/cmathmodule.c

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -324,36 +324,6 @@ cmath_atan_impl(PyObject *module, Py_complex z)
324324
return r;
325325
}
326326

327-
/* Windows screws up atan2 for inf and nan, and alpha Tru64 5.1 doesn't follow
328-
C99 for atan2(0., 0.). */
329-
static double
330-
c_atan2(Py_complex z)
331-
{
332-
if (isnan(z.real) || isnan(z.imag))
333-
return Py_NAN;
334-
if (isinf(z.imag)) {
335-
if (isinf(z.real)) {
336-
if (copysign(1., z.real) == 1.)
337-
/* atan2(+-inf, +inf) == +-pi/4 */
338-
return copysign(0.25*Py_MATH_PI, z.imag);
339-
else
340-
/* atan2(+-inf, -inf) == +-pi*3/4 */
341-
return copysign(0.75*Py_MATH_PI, z.imag);
342-
}
343-
/* atan2(+-inf, x) == +-pi/2 for finite x */
344-
return copysign(0.5*Py_MATH_PI, z.imag);
345-
}
346-
if (isinf(z.real) || z.imag == 0.) {
347-
if (copysign(1., z.real) == 1.)
348-
/* atan2(+-y, +inf) = atan2(+-0, +x) = +-0. */
349-
return copysign(0., z.imag);
350-
else
351-
/* atan2(+-y, -inf) = atan2(+-0., -x) = +-pi. */
352-
return copysign(Py_MATH_PI, z.imag);
353-
}
354-
return atan2(z.imag, z.real);
355-
}
356-
357327

358328
static Py_complex atanh_special_values[7][7];
359329

@@ -966,7 +936,7 @@ cmath_phase_impl(PyObject *module, Py_complex z)
966936
double phi;
967937

968938
errno = 0;
969-
phi = c_atan2(z); /* should not cause any exception */
939+
phi = m_atan2(z.imag, z.real); /* should not cause any exception */
970940
if (errno != 0)
971941
return math_error();
972942
else
@@ -991,7 +961,7 @@ cmath_polar_impl(PyObject *module, Py_complex z)
991961
double r, phi;
992962

993963
errno = 0;
994-
phi = c_atan2(z); /* should not cause any exception */
964+
phi = m_atan2(z.imag, z.real); /* should not cause any exception */
995965
r = _Py_c_abs(z); /* sets errno to ERANGE on overflow */
996966
if (errno != 0)
997967
return math_error();

Modules/mathmodule.c

Lines changed: 0 additions & 37 deletions

0 commit comments

Comments
 (0)