Skip to content

gh-155966: Correct handling of tanpi(0.5) (#155966) - #155980

Open
jepler wants to merge 5 commits into
python:mainfrom
jepler:issue-155966
Open

gh-155966: Correct handling of tanpi(0.5) (#155966)#155980
jepler wants to merge 5 commits into
python:mainfrom
jepler:issue-155966

Conversation

@jepler

@jepler jepler commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

As pointed out in #155966, 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.

In the process of working on this, I noticed that I had incorrectly added duplicate test ids and that this was not treated as an error by the test harness. I have corrected this and made it part of the test.

jepler added 3 commits August 17, 2026 17:26
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.
Comment thread Misc/NEWS.d/next/Library/2026-08-17-17-39-41.gh-issue-155966.0YOADY.rst Outdated
Comment on lines +2253 to +2254
tanpi30115 tanpi 1.5 -> inf invalid
tanpi30118 tanpi -1.5 -> inf invalid

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Standard says: tanpi(n + 1/2) returns -oo and raises the "divide-by-zero" floating-point exception, for odd integers n.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My reference (draft ISO/IEC 9899:2023 F.10.1.14) has this:

— tanpi(n + 1/2 ) returns +∞ and raises the “divide-by-zero” floating-point exception, for even integers n.
— tanpi(n + 1/2 ) returns +∞ and raises the “divide-by-zero” floating-point exception, for odd integers n.

I don't think the test harness can actually verify the return value of the underlying C API since it was consumed when the exception is generated. In a standalone C program I verified that the signs of infinity for the m_atanpi implementation I provided match the GNU C library implementation. (In fact you can even write something like -> 7 invalid for these exception cases and the test harness gives a pass)

I can still correct the signs of infinity shown here, is that what you're requesting?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the test harness can actually verify the return value of the underlying C API since it was consumed when the exception is generated.

Yes, though it's better to match the standard. Maybe in future we can have access to such values, see e.g. #133895.

Comment on lines +1318 to +1320
atan2pi22003 atan2pi inf 1 -> 0.5
atan2pi22004 atan2pi -inf 1 -> -0.5
atan2pi22005 atan2pi nan 1 -> nan

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those ids not clash with other. Lets revert such changes.

Keep only:

AssertionError: Failures in test_mtestfile:
  Duplicate test id atan2pi20000
  Duplicate test id atan2pi20001
  Duplicate test id atan2pi20002
  Duplicate test id atan2pi30000
  Duplicate test id atan2pi30001
  Duplicate test id atan2pi30002

…YOADY.rst

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants