Skip to content

Commit 886d4ac

Browse files
committed
gh-155966: Correct handling of tanpi(0.5) (#155966)
As pointed out in the issue, the exceptional half-integer (0.5, 1.5, etc) inputs of tanpi were not handled properly. Now, these raise ValueError and this is tested by `test.test_math` through its list of test cases.
1 parent a7bb524 commit 886d4ac

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

Lib/test/mathdata/math_testcases.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2247,3 +2247,8 @@ tanpi10275 tanpi -1.6591963470121216 -> 1.829921944286168
22472247
tanpi20001 tanpi inf -> nan invalid
22482248
tanpi20002 tanpi -inf -> nan invalid
22492249
tanpi20003 tanpi nan -> nan
2250+
2251+
tanpi30050 tanpi 0.5 -> inf invalid
2252+
tanpi30055 tanpi -0.5 -> inf invalid
2253+
tanpi30115 tanpi 1.5 -> inf invalid
2254+
tanpi30118 tanpi -1.5 -> inf invalid

Modules/mathmodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,10 +1343,10 @@ FUNC1D(tan, tan, 0,
13431343
FUNC1(tanh, tanh, 0,
13441344
"tanh($module, x, /)\n--\n\n"
13451345
"Return the hyperbolic tangent of x.")
1346-
FUNC1D(tanpi, m_tanpi, 1,
1346+
FUNC1D(tanpi, m_tanpi, 0,
13471347
"tanpi($module, x, /)\n--\n\n"
13481348
"Return the tangent of x (measured in half-turns).",
1349-
"expected a finite input, got %s")
1349+
"expected a finite input not equal to a half-integer, got %s")
13501350

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

0 commit comments

Comments
 (0)