Skip to content

Commit b6e6613

Browse files
authored
gh-150534: Add C23 half-turn trigonometric *pi functions (GH-150555)
Add the the following functions to the math module: acospi, asinpi, atanpi, atan2pi, cospi, sinpi, tanpi.
1 parent fab449b commit b6e6613

9 files changed

Lines changed: 1952 additions & 24 deletions

File tree

Doc/library/math.rst

Lines changed: 71 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,20 @@ noted otherwise, all return values are floats.
8383

8484
**Trigonometric functions**
8585
--------------------------------------------------------------------------------------------------
86-
:func:`acos(x) <acos>` Arc cosine of *x*
87-
:func:`asin(x) <asin>` Arc sine of *x*
88-
:func:`atan(x) <atan>` Arc tangent of *x*
89-
:func:`atan2(y, x) <atan2>` ``atan(y / x)``
90-
:func:`cos(x) <cos>` Cosine of *x*
91-
:func:`sin(x) <sin>` Sine of *x*
92-
:func:`tan(x) <tan>` Tangent of *x*
86+
:func:`acos(x) <acos>` Arc cosine of *x*, in radians
87+
:func:`acospi(x) <acospi>` Arc cosine of *x*, in half-turns
88+
:func:`asin(x) <asin>` Arc sine of *x*, in radians
89+
:func:`asinpi(x) <asinpi>` Arc sine of *x*, in half-turns
90+
:func:`atan(x) <atan>` Arc tangent of *x*, in radians
91+
:func:`atanpi(x) <atanpi>` Arc tangent of *x*, in half-turns
92+
:func:`atan2(y, x) <atan2>` ``atan(y / x)``, in radians
93+
:func:`atan2pi(y, x) <atan2pi>` ``atan(y / x)``, in half-turns
94+
:func:`cos(x) <cos>` Cosine of *x* radians
95+
:func:`cospi(x) <cospi>` Cosine of *x⋅π* radians
96+
:func:`sin(x) <sin>` Sine of *x* radians
97+
:func:`sinpi(x) <sinpi>` Sine of *x⋅π* radians
98+
:func:`tan(x) <tan>` Tangent of *x* radians
99+
:func:`tanpi(x) <tanpi>` Tangent of *x⋅π* radians
93100

94101
**Hyperbolic functions**
95102
--------------------------------------------------------------------------------------------------
@@ -599,18 +606,42 @@ Trigonometric functions
599606
``pi``.
600607

601608

609+
.. function:: acospi(x)
610+
611+
Return the arc cosine of *x*, in half-turns. The result is between ``0`` and
612+
``1``.
613+
614+
.. versionadded:: next
615+
616+
602617
.. function:: asin(x)
603618

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

607622

623+
.. function:: asinpi(x)
624+
625+
Return the arc sine of *x*, in half-turns. The result is between ``-0.5`` and
626+
``0.5``.
627+
628+
.. versionadded:: next
629+
630+
608631
.. function:: atan(x)
609632

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

613636

637+
.. function:: atanpi(x)
638+
639+
Return the arc tangent of *x*, in half-turns. The result is between ``-0.5`` and
640+
``0.5``.
641+
642+
.. versionadded:: next
643+
644+
614645
.. function:: atan2(y, x)
615646

616647
Return ``atan(y / x)``, in radians. The result is between ``-pi`` and ``pi``.
@@ -621,21 +652,54 @@ Trigonometric functions
621652
-1)`` is ``-3*pi/4``.
622653

623654

655+
.. function:: atan2pi(y, x)
656+
657+
Return ``atanpi(y / x)``, in half-turns. The result is between ``-1`` and ``1``.
658+
The vector in the plane from the origin to point ``(x, y)`` makes this angle
659+
with the positive X axis. The point of :func:`atan2pi` is that the signs of both
660+
inputs are known to it, so it can compute the correct quadrant for the angle.
661+
For example, ``atanpi(1)`` and ``atan2pi(1, 1)`` are both ``0.25``, but
662+
``atan2pi(-1, -1)`` is ``-0.75``.
663+
664+
.. versionadded:: next
665+
666+
624667
.. function:: cos(x)
625668

626669
Return the cosine of *x* radians.
627670

628671

672+
.. function:: cospi(x)
673+
674+
Return the cosine of *x* half-turns (*x⋅π* radians).
675+
676+
.. versionadded:: next
677+
678+
629679
.. function:: sin(x)
630680

631681
Return the sine of *x* radians.
632682

633683

684+
.. function:: sinpi(x)
685+
686+
Return the sine of *x* half-turns (*x⋅π* radians).
687+
688+
.. versionadded:: next
689+
690+
634691
.. function:: tan(x)
635692

636693
Return the tangent of *x* radians.
637694

638695

696+
.. function:: tanpi(x)
697+
698+
Return the tangent of *x* half-turns (*x⋅π* radians).
699+
700+
.. versionadded:: next
701+
702+
639703
Hyperbolic functions
640704
--------------------
641705

Doc/whatsnew/3.16.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,17 @@ logging
113113
before the rotation interval expires.
114114
(Contributed by Iván Márton and Serhiy Storchaka in :gh:`84649`.)
115115

116+
math
117+
----
118+
119+
* Added trigonometric functions that work in units of half turns, rather than
120+
radians. The new functions :func:`math.acospi`, :func:`math.asinpi`,
121+
:func:`math.atanpi`, and :func:`math.atan2pi` return half-turn angles. The
122+
new functions :func:`math.cospi`, :func:`math.sinpi`, and :func:`math.tanpi`
123+
take half-turn angle arguments. These functions are recommended by IEEE
124+
754-2019 and standardized in C23.
125+
(Contributed by Jeff Epler in :gh:`150534`.)
126+
116127
os
117128
--
118129

0 commit comments

Comments
 (0)