Skip to content

math.tanpi is untested at its poles and no test-file flag fits #155966

Description

@fedonman

Bug description:

math.tanpi is singular at every odd half-integer, and m_tanpi in Modules/mathmodule.c has an explicit branch for that case, but nothing exercises it. None of the 279 tanpi rows in Lib/test/mathdata/math_testcases.txt has a half-integer argument, and Lib/test/test_math.py never names tanpi.

Adding a row for it does not work as written, because the flag that describes this case makes test_mtestfile fail:

$ echo 'tanpi20004 tanpi 0.5 -> inf divide-by-zero' >> Lib/test/mathdata/math_testcases.txt
$ ./python -m test test_math -m test_mtestfile
...
AssertionError: Failures in test_mtestfile:
  tanpi20004: tanpi[0.5]: expected 'ValueError', got 'OverflowError' (not equal)
...
Result: FAILURE

The header of math_testcases.txt defines divide-by-zero as "raised when a finite input gives a mathematically infinite result", which is what happens at the pole, and test_mtestfile maps that flag to ValueError, while math.tanpi(0.5) raises OverflowError. The other flag, overflow, passes, but the same header defines it as "raised when a finite input gives a finite result that is too large to fit in the usual range of an IEEE 754 double", so the row would record something the file says is false.

Doc/library/math.rst does not mention the poles either.

Expected: math.tanpi at an odd half-integer is covered by a test, with a flag that matches the file's own definitions.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.16new features, bugs and security fixesextension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions