ENH: Add np.sinpi et al following CPython core, C23 & IEEE754-2019
"Jeff Epler" <[email protected]> Mon, 08 Jun 2026 08:59:24 -0500
| Newsgroups | gmane.comp.python.numeric.general |
|---|---|
| Message-ID | <[email protected]> |
--===============7376113616834423554== Content-Type: multipart/alternative; boundary=da638da498459bfc739d02269636b51dec45ac3b --da638da498459bfc739d02269636b51dec45ac3b Content-Type: text/plain Content-Transfer-Encoding: 7bit In a recently merged PR (https://github.com/python/cpython/pull/150555), CPython has added a family of "*pi" functions to the math module, which take half-turn arguments instead of radians. One reason these functions are advantageous is that it's easy to provide the property that `sinpi(n/2)` is exact for all integers n, while `sin(pi*n)` is never exactly equal to the mathematical ideal except for n=0. These functions are recommended by IEEE754-2019 and standardized in C23 Annex G. (note: I'm reading C23 draft revised 2023-01-24, not the final standard document; and I do not have IEEE754-2019). C23 and CPython only added the real-valued versions of these functions, but C23 "future library directions" notes that identifiers like `csinpi` are "potentially reserved identifiers." Since CPython only requires C11, CPython includes implementations of these functions for when the underling platform library does not provide it. These implementations work by performing special case handling & range reduction, followed by a call to the standard trig function with a scaled argument (in the case of forward functions) or scaling of the result (in the case of inverse/arc functions). I am interested in doing the numpy implementation, however I have never done core numpy work before. If there is interest from the project, I would like to initially offer a PR containing a single function such as `sinpi` and then complete the others following numpy core developer feedback. Thanks, Jeff PS I notice via the archives that there are occasional "New Contributors' Hour" meetings. Is the next one scheduled yet? --da638da498459bfc739d02269636b51dec45ac3b Content-Type: text/html Content-Transfer-Encoding: quoted-printable <!DOCTYPE html><html><head><title></title></head><body><div>In a recentl= y merged PR (https://github.com/python/cpython/pull/150555), CPython has= added a family of "*pi" functions to the math module, which take half-t= urn arguments instead of radians. One reason these functions are advanta= geous is that it's easy to provide the property that `sinpi(n/2)` is exa= ct for all integers n, while `sin(pi*n)` is never exactly equal to the m= athematical ideal except for n=3D0.</div><div><br></div><div>These funct= ions are recommended by IEEE754-2019 and standardized in C23 Annex G. (n= ote: I'm reading C23 draft revised 2023-01-24, not the final standard do= cument; and I do not have IEEE754-2019).</div><div><br></div><div>C23 an= d CPython only added the real-valued versions of these functions, but C2= 3 "future library directions" notes that identifiers like `csinpi` are "= potentially reserved identifiers."</div><div><br></div><div>Since CPytho= n only requires C11, CPython includes implementations of these functions= for when the underling platform library does not provide it. These impl= ementations work by performing special case handling & range reducti= on, followed by a call to the standard trig function with a scaled argum= ent (in the case of forward functions) or scaling of the result (in the = case of inverse/arc functions).</div><div><br></div><div>I am interested= in doing the numpy implementation, however I have never done core numpy= work before. If there is interest from the project, I would like to ini= tially offer a PR containing a single function such as `sinpi` and then = complete the others following numpy core developer feedback.</div><div><= br></div><div>Thanks,</div><div>Jeff</div><div>PS I notice via the archi= ves that there are occasional "New Contributors' Hour" meetings. Is the = next one scheduled yet?<br></div></body></html> --da638da498459bfc739d02269636b51dec45ac3b-- --===============7376113616834423554== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ NumPy-Discussion mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/numpy-discussion.python.org Member address: [email protected] --===============7376113616834423554==--