Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
ad12476
Add *pi functions to math module
jepler May 27, 2026
03808d6
Add news item and remove testing code
jepler May 27, 2026
e9ec2b6
tests: Add math_testcases for the new *pi functions
jepler May 28, 2026
bb57325
fix discussion of atan2pi
jepler May 28, 2026
7650fa5
fix wrongly changed m_sinpi
jepler May 28, 2026
86de1c0
regenerate autoconf files with `make regen-configure`
jepler May 28, 2026
be980bf
remove accidentally-committed code
jepler May 29, 2026
d3254cd
mathdata: Add +-inf, nan tests for new functions
jepler May 29, 2026
6d8dd17
test_math: Let "mtestfile" test 2-arg functions
jepler May 29, 2026
0c7fdfb
math_testcases: Add testcases for atan2pi
jepler May 29, 2026
aa93326
These are now tested in math_testcases.txt
jepler May 29, 2026
e0ede77
Add whatsnew entry for math module changes
jepler May 29, 2026
694f479
Correct doc typos (atanpi2 -> atan2pi)
jepler May 29, 2026
ab68cdc
Correct comment about which standard this conforms to
jepler May 29, 2026
359ac19
Add 'versionadded' notes to new functions
jepler May 29, 2026
6cec4b8
Use float constants, not expressions, for simple values.
jepler May 29, 2026
d66a2c3
as x is finite, regular comparisons can be used here
jepler May 29, 2026
dcc5040
Merge remote-tracking branch 'origin/main' into c23-math-pifuns
jepler May 29, 2026
1f98ce6
remove comment about glibc
jepler May 30, 2026
12fcd24
Update comments based on review.
jepler May 30, 2026
56da6fc
math_methods: Re-sort and conform to surrounding spacing
jepler May 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 71 additions & 7 deletions Doc/library/math.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,20 @@ noted otherwise, all return values are floats.

**Trigonometric functions**
--------------------------------------------------------------------------------------------------
:func:`acos(x) <acos>` Arc cosine of *x*
:func:`asin(x) <asin>` Arc sine of *x*
:func:`atan(x) <atan>` Arc tangent of *x*
:func:`atan2(y, x) <atan2>` ``atan(y / x)``
:func:`cos(x) <cos>` Cosine of *x*
:func:`sin(x) <sin>` Sine of *x*
:func:`tan(x) <tan>` Tangent of *x*
:func:`acos(x) <acos>` Arc cosine of *x*, in radians
Comment thread
skirpichev marked this conversation as resolved.
:func:`acospi(x) <acospi>` Arc cosine of *x*, in half-turns
Comment thread
hugovk marked this conversation as resolved.
:func:`asin(x) <asin>` Arc sine of *x*, in radians
:func:`asinpi(x) <asinpi>` Arc sine of *x*, in half-turns
:func:`atan(x) <atan>` Arc tangent of *x*, in radians
:func:`atanpi(x) <atanpi>` Arc tangent of *x*, in half-turns
:func:`atan2(y, x) <atan2>` ``atan(y / x)``, in radians
:func:`atan2pi(y, x) <atan2pi>` ``atan(y / x)``, in half-turns
:func:`cos(x) <cos>` Cosine of *x* radians
:func:`cospi(x) <cospi>` Cosine of *x⋅π* radians
:func:`sin(x) <sin>` Sine of *x* radians
:func:`sinpi(x) <sinpi>` Sine of *x⋅π* radians
:func:`tan(x) <tan>` Tangent of *x* radians
:func:`tanpi(x) <tanpi>` Tangent of *x⋅π* radians

**Hyperbolic functions**
--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -597,18 +604,42 @@ Trigonometric functions
``pi``.


.. function:: acospi(x)

Return the arc cosine of *x*, in half-turns. The result is between ``0`` and
``1``.

Comment thread
skirpichev marked this conversation as resolved.
.. versionadded:: next


.. function:: asin(x)

Return the arc sine of *x*, in radians. The result is between ``-pi/2`` and
``pi/2``.


.. function:: asinpi(x)

Return the arc sine of *x*, in half-turns. The result is between ``-0.5`` and
``0.5``.

.. versionadded:: next


.. function:: atan(x)

Return the arc tangent of *x*, in radians. The result is between ``-pi/2`` and
``pi/2``.


.. function:: atanpi(x)

Return the arc tangent of *x*, in half-turns. The result is between ``-0.5`` and
``0.5``.

.. versionadded:: next


.. function:: atan2(y, x)

Return ``atan(y / x)``, in radians. The result is between ``-pi`` and ``pi``.
Expand All @@ -619,21 +650,54 @@ Trigonometric functions
-1)`` is ``-3*pi/4``.


.. function:: atan2pi(y, x)

Return ``atanpi(y / x)``, in half-turns. The result is between ``-1`` and ``1``.
The vector in the plane from the origin to point ``(x, y)`` makes this angle
with the positive X axis. The point of :func:`atan2pi` is that the signs of both
inputs are known to it, so it can compute the correct quadrant for the angle.
For example, ``atanpi(1)`` and ``atan2pi(1, 1)`` are both ``.25``, but
``atan2pi(-1, -1)`` is ``-.75``.
Comment on lines +659 to +660
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.

Suggested change
For example, ``atanpi(1)`` and ``atan2pi(1, 1)`` are both ``.25``, but
``atan2pi(-1, -1)`` is ``-.75``.
For example, ``atanpi(1)`` and ``atan2pi(1, 1)`` are both ``0.25``, but
``atan2pi(-1, -1)`` is ``-0.75``.

Let's be consistent with fractional values.


.. versionadded:: next


.. function:: cos(x)

Return the cosine of *x* radians.


.. function:: cospi(x)

Return the cosine of *x* half-turns (*x⋅π* radians).

.. versionadded:: next


.. function:: sin(x)

Return the sine of *x* radians.


.. function:: sinpi(x)

Return the sine of *x* half-turns (*x⋅π* radians).

.. versionadded:: next


.. function:: tan(x)

Return the tangent of *x* radians.


.. function:: tanpi(x)

Return the tangent of *x* half-turns (*x⋅π* radians).

.. versionadded:: next


Hyperbolic functions
--------------------

Expand Down
10 changes: 10 additions & 0 deletions Doc/whatsnew/3.16.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ lzma
requires ``lzma`` 5.4.0 or newer while RISC-V requires 5.6.0 or newer.
(Contributed by Chien Wong in :gh:`115988`.)

math
----

* Added trigonometric functions that work in units of half turns, rather than
radians. The new functions :func:`math.acospi`, :func:`math.asinpi`,
:func:`math.atanpi`, and :func:`math.atan2pi` return half-turn angles. The
new functions :func:`math.cospi`, :func:`math.sinpi`, and :func:`math.tanpi`
take half-turn angle arguments. These functions are recommended by IEEE
754-2019 and standardized in C23.

os
--

Expand Down
Loading
Loading