gh-150534: Add C23 half-turn trigonometric *pi functions#150555
gh-150534: Add C23 half-turn trigonometric *pi functions#150555jepler wants to merge 21 commits into
*pi functions#150555Conversation
* Add tests * Add documentation * Add configure-time checks for function presence * Regenerate configure No news item added, pending creation of a github issue. As committed, the local implementation of the functions is always used. For production, the #undefs should be removed so that the presence of the functions is detected by configure and used by mathmodule.
Documentation build overview
11 files changed ·
|
|
|
||
| acospi10000 acospi 0.0 -> 0.5 | ||
| acospi10001 acospi -0.0 -> 0.5 | ||
| acospi10002 acospi 1.0 -> 0.0 |
There was a problem hiding this comment.
Please also test infinite/nan input and values with magnitude > 1. Include appropriate FPE flags, where it's required by the C23 Annex F.
With this, I think you can drop separate tests in the test_math.py for new functions.
serhiy-storchaka
left a comment
There was a problem hiding this comment.
Please add also a What's New entry.
|
|
||
| .. function:: atanpi(x) | ||
|
|
||
| Return the arc tangent of *x*, in half-turns. The result is between ``-1/2`` and |
There was a problem hiding this comment.
Since the result is a float, should not we use 0.5 instead 0f 1/2? The same question for other documentation and examples.
There was a problem hiding this comment.
That's a great question. These doc blocks were made by copypaste of the existing block (e.g., atan) then removing pi.
It's clear why an expression using pi is used in the existing atan2 docs. However, it's possible to ask which would be clearer in the atan2 comment: -.75*pi or -3*pi/4. I feel like the answer to this might make it clear whether -.75 or -3/4 is clearer in the new function's documentation.
Thoughts?
There was a problem hiding this comment.
-3*pi/4 is an expression. I think it is clearer in such way. But for atan2pi we can use exact number: -0.75.
I don't have a firm opinion, I'm just pointing out a possible option. I am fine with any option.
.. as suggested in review
|
Branch updated based on review comments. Thank you for your reviews. |
Also use the surrounding style of two spaces after a sentence- ending period.
|
I've updated the PR with additional comment changes as requested. |
| For example, ``atanpi(1)`` and ``atan2pi(1, 1)`` are both ``.25``, but | ||
| ``atan2pi(-1, -1)`` is ``-.75``. |
There was a problem hiding this comment.
| 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.
| {"atan2", _PyCFunction_CAST(math_atan2), METH_FASTCALL, math_atan2_doc}, | ||
| {"atanh", math_atanh, METH_O, math_atanh_doc}, | ||
| {"atan2pi", _PyCFunction_CAST(math_atan2pi), METH_FASTCALL, math_atan2pi_doc}, | ||
| {"atanpi", math_atanpi, METH_O, math_atanpi_doc}, |
There was a problem hiding this comment.
{"atanpi", math_atanpi, METH_O, math_atanpi_doc},make it aligned with METH_O of atanh
*pi functions
skirpichev
left a comment
There was a problem hiding this comment.
LGTM, with few remaining comments
| #define m_cospi cospi | ||
| #endif | ||
|
|
||
|
|
There was a problem hiding this comment.
Make it consistent with the rest:
| 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. | ||
|
|
There was a problem hiding this comment.
| (Contributed by Jeff Epler in :gh:`150534`.) | |
See #150534 and https://discuss.python.org/t/add-half-turns-functions-cospi-et-al-to-math-module-following-c23-ieee754-2019/107550/5 for discussion and context.
The following functions are added to the math module:
The following aspects of a new feature are covered in this pull request:
The
math_testcases.txtcases are based on glibc's test cases, and their input & output values have been used. I supplemented this with tests of inf/nan arguments.I extended
math_testcases.txtso that it can test n-arg functions, and used it to test atan2pi.Closes: #150534