Skip to content
17 changes: 11 additions & 6 deletions Lib/test/mathdata/math_testcases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1311,9 +1311,9 @@ atan2pi20000 atan2pi inf 0 -> 0.5
atan2pi20001 atan2pi -inf 0 -> -0.5
atan2pi20002 atan2pi nan 0 -> nan

atan2pi20000 atan2pi inf -0 -> 0.5
atan2pi20001 atan2pi -inf -0 -> -0.5
atan2pi20002 atan2pi nan -0 -> nan
atan2pi21000 atan2pi inf -0 -> 0.5
atan2pi21001 atan2pi -inf -0 -> -0.5
atan2pi21002 atan2pi nan -0 -> nan

atan2pi20003 atan2pi inf 1 -> 0.5
atan2pi20004 atan2pi -inf 1 -> -0.5
Expand All @@ -1339,9 +1339,9 @@ atan2pi30000 atan2pi 0 inf -> 0.0
atan2pi30001 atan2pi 0 -inf -> 1.0
atan2pi30002 atan2pi 0 nan -> nan

atan2pi30000 atan2pi -0 inf -> -0.0
atan2pi30001 atan2pi -0 -inf -> -1.0
atan2pi30002 atan2pi -0 nan -> nan
atan2pi31000 atan2pi -0 inf -> -0.0
atan2pi31001 atan2pi -0 -inf -> -1.0
atan2pi31002 atan2pi -0 nan -> nan

atan2pi30003 atan2pi 1 inf -> 0.0
atan2pi30004 atan2pi 1 -inf -> 1.0
Expand Down Expand Up @@ -2247,3 +2247,8 @@ tanpi10275 tanpi -1.6591963470121216 -> 1.829921944286168
tanpi20001 tanpi inf -> nan invalid
tanpi20002 tanpi -inf -> nan invalid
tanpi20003 tanpi nan -> nan

tanpi30001 tanpi 0.5 -> inf divide-by-zero
tanpi30002 tanpi -0.5 -> -inf divide-by-zero
tanpi30003 tanpi 1.5 -> -inf divide-by-zero
tanpi30004 tanpi -1.5 -> inf divide-by-zero
5 changes: 5 additions & 0 deletions Lib/test/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -2144,7 +2144,12 @@ def test_mtestfile(self):
fail_fmt = "{}: {}{!r}: {}"

failures = []
ids = set()
for id, fn, args, expected, flags in parse_mtestfile(math_testcases):
if id in ids:
failures.append(f"Duplicate test id {id}")
ids.add(id)

func = getattr(math, fn)

if 'invalid' in flags or 'divide-by-zero' in flags:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:func:`math.tanpi` now raises :exc:`ValueError` for half-integer values
(e.g., ``tanpi(1.5)``), as these are poles of the function.
4 changes: 2 additions & 2 deletions Modules/mathmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1343,10 +1343,10 @@ FUNC1D(tan, tan, 0,
FUNC1(tanh, tanh, 0,
"tanh($module, x, /)\n--\n\n"
"Return the hyperbolic tangent of x.")
FUNC1D(tanpi, m_tanpi, 1,
FUNC1D(tanpi, m_tanpi, 0,
"tanpi($module, x, /)\n--\n\n"
"Return the tangent of x (measured in half-turns).",
"expected a finite input, got %s")
"expected a finite input not equal to a half-integer, got %s")

/* Precision summation function as msum() by Raymond Hettinger in
<https://code.activestate.com/recipes/393090-binary-floating-point-summation-accurate-to-full-p/>,
Expand Down
Loading