Skip to content

Commit c096fad

Browse files
committed
gh-122681: remove m_atan2()/c_atan2() helpers
1 parent 44659d3 commit c096fad

File tree

2 files changed

+3
-70
lines changed

2 files changed

+3
-70
lines changed

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 = 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 = 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: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -535,43 +535,6 @@ m_lgamma(double x)
535535
return r;
536536
}
537537

538-
/*
539-
wrapper for atan2 that deals directly with special cases before
540-
delegating to the platform libm for the remaining cases. This
541-
is necessary to get consistent behaviour across platforms.
542-
Windows, FreeBSD and alpha Tru64 are amongst platforms that don't
543-
always follow C99.
544-
*/
545-
546-
static double
547-
m_atan2(double y, double x)
548-
{
549-
if (isnan(x) || isnan(y))
550-
return Py_NAN;
551-
if (isinf(y)) {
552-
if (isinf(x)) {
553-
if (copysign(1., x) == 1.)
554-
/* atan2(+-inf, +inf) == +-pi/4 */
555-
return copysign(0.25*Py_MATH_PI, y);
556-
else
557-
/* atan2(+-inf, -inf) == +-pi*3/4 */
558-
return copysign(0.75*Py_MATH_PI, y);
559-
}
560-
/* atan2(+-inf, x) == +-pi/2 for finite x */
561-
return copysign(0.5*Py_MATH_PI, y);
562-
}
563-
if (isinf(x) || y == 0.) {
564-
if (copysign(1., x) == 1.)
565-
/* atan2(+-y, +inf) = atan2(+-0, +x) = +-0. */
566-
return copysign(0., y);
567-
else
568-
/* atan2(+-y, -inf) = atan2(+-0., -x) = +-pi. */
569-
return copysign(Py_MATH_PI, y);
570-
}
571-
return atan2(y, x);
572-
}
573-
574-
575538
/* IEEE 754-style remainder operation: x - n*y where n*y is the nearest
576539
multiple of y to x, taking n even in the case of a tie. Assuming an IEEE 754
577540
binary floating-point format, the result is always exact. */
@@ -1103,7 +1066,7 @@ FUNC1(atan, atan, 0,
11031066
"atan($module, x, /)\n--\n\n"
11041067
"Return the arc tangent (measured in radians) of x.\n\n"
11051068
"The result is between -pi/2 and pi/2.")
1106-
FUNC2(atan2, m_atan2,
1069+
FUNC2(atan2, atan2,
11071070
"atan2($module, y, x, /)\n--\n\n"
11081071
"Return the arc tangent (measured in radians) of y/x.\n\n"
11091072
"Unlike atan(y/x), the signs of both x and y are considered.")

0 commit comments

Comments
 (0)