Re: ENH: Add np.sinpi et al following CPython core, C23 & IEEE754-2019
Lucas Colley via NumPy-Discussion <[email protected]> Tue, 9 Jun 2026 17:08:24 +0100
| Newsgroups | gmane.comp.python.numeric.general |
|---|---|
| Message-ID | <[email protected]> |
--===============0677280979476835086== Content-Type: multipart/alternative; boundary="Apple-Mail=_8F9D6D18-D614-4952-8001-CFBEC5422ADF" --Apple-Mail=_8F9D6D18-D614-4952-8001-CFBEC5422ADF Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 There was a proposal to add these to `scipy.special`: = https://discuss.scientific-python.org/t/rfc-add-sinpi-cospi-tanpi-and-cotp= i-functions-to-special/1193. There are existing implementations at = https://github.com/scipy/xsf/blob/main/include/xsf/trig.h , with `sinpi` = and `cospi` exposed to SciPy (privately) at = https://github.com/scipy/scipy/blob/main/scipy/special/xsf_wrappers.h#L394= -L396. We should probably decide whether these best belong in `numpy` or = `scipy.special`, and only expose them in one of the two. Cheers, Lucas > On 9 Jun 2026, at 16:23, Jerome Kieffer <[email protected]> = wrote: >=20 > I like the idea ! >=20 > On Mon, 08 Jun 2026 08:59:24 -0500 > "Jeff Epler" <[email protected] <mailto:[email protected]>> = wrote: >=20 >> 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=3D0. >>=20 >> 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). >>=20 >> 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." >>=20 >> 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). >>=20 >> 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. >>=20 >> Thanks, >> Jeff >> PS I notice via the archives that there are occasional "New = Contributors' Hour" meetings. Is the next one scheduled yet? >=20 >=20 >=20 >=20 > --=20 > J=C3=A9r=C3=B4me Kieffer > tel +33 476 882 445 > _______________________________________________ > NumPy-Discussion mailing list -- [email protected] = <mailto:[email protected]> > To unsubscribe send an email to [email protected] = <mailto:[email protected]> > https://mail.python.org/mailman3//lists/numpy-discussion.python.org > Member address: [email protected] = <mailto:[email protected]> --Apple-Mail=_8F9D6D18-D614-4952-8001-CFBEC5422ADF Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 <html aria-label=3D"message body"><head><meta http-equiv=3D"content-type" = content=3D"text/html; charset=3Dutf-8"></head><body = style=3D"overflow-wrap: break-word; -webkit-nbsp-mode: space; = line-break: after-white-space;">There was a proposal to add these to = `scipy.special`: <a = href=3D"https://discuss.scientific-python.org/t/rfc-add-sinpi-cospi-tanpi-= and-cotpi-functions-to-special/1193">https://discuss.scientific-python.org= /t/rfc-add-sinpi-cospi-tanpi-and-cotpi-functions-to-special/1193</a>. = There are existing implementations at <a = href=3D"https://github.com/scipy/xsf/blob/main/include/xsf/trig.h">https:/= /github.com/scipy/xsf/blob/main/include/xsf/trig.h</a> , with = `sinpi` and `cospi` exposed to SciPy (privately) at <a = href=3D"https://github.com/scipy/scipy/blob/main/scipy/special/xsf_wrapper= s.h#L394-L396">https://github.com/scipy/scipy/blob/main/scipy/special/xsf_= wrappers.h#L394-L396</a>.<div><br></div><div>We should probably decide = whether these best belong in `numpy` or `scipy.special`, and only expose = them in one of the = two.<br><div><br></div><div>Cheers,</div><div>Lucas<br = id=3D"lineBreakAtBeginningOfMessage"><div><br><blockquote = type=3D"cite"><div>On 9 Jun 2026, at 16:23, Jerome Kieffer = <[email protected]> wrote:</div><br = class=3D"Apple-interchange-newline"><div><meta charset=3D"UTF-8"><span = style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: = 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; = letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; = text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; = -webkit-text-stroke-width: 0px; text-decoration: none; float: none; = display: inline !important;">I like the idea !</span><br = style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: = 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; = letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; = text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; = -webkit-text-stroke-width: 0px; text-decoration-line: none; = text-decoration-thickness: auto; text-decoration-style: solid;"><br = style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: = 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; = letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; = text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; = -webkit-text-stroke-width: 0px; text-decoration-line: none; = text-decoration-thickness: auto; text-decoration-style: solid;"><span = style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: = 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; = letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; = text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; = -webkit-text-stroke-width: 0px; text-decoration: none; float: none; = display: inline !important;">On Mon, 08 Jun 2026 08:59:24 = -0500</span><br style=3D"caret-color: rgb(0, 0, 0); font-family: = Helvetica; font-size: 12px; font-style: normal; font-variant-caps: = normal; font-weight: 400; letter-spacing: normal; orphans: 2; = text-align: start; text-indent: 0px; text-transform: none; white-space: = normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; = text-decoration-line: none; text-decoration-thickness: auto; = text-decoration-style: solid;"><span style=3D"caret-color: rgb(0, 0, 0); = font-family: Helvetica; font-size: 12px; font-style: normal; = font-variant-caps: normal; font-weight: 400; letter-spacing: normal; = orphans: 2; text-align: start; text-indent: 0px; text-transform: none; = white-space: normal; widows: 2; word-spacing: 0px; = -webkit-text-stroke-width: 0px; text-decoration: none; float: none; = display: inline !important;">"Jeff Epler" <</span><a = href=3D"mailto:[email protected]" style=3D"font-family: Helvetica; = font-size: 12px; font-style: normal; font-variant-caps: normal; = font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; = text-indent: 0px; text-transform: none; white-space: normal; widows: 2; = word-spacing: 0px; -webkit-text-stroke-width: = 0px;">[email protected]</a><span style=3D"caret-color: rgb(0, 0, 0); = font-family: Helvetica; font-size: 12px; font-style: normal; = font-variant-caps: normal; font-weight: 400; letter-spacing: normal; = orphans: 2; text-align: start; text-indent: 0px; text-transform: none; = white-space: normal; widows: 2; word-spacing: 0px; = -webkit-text-stroke-width: 0px; text-decoration: none; float: none; = display: inline !important;">> wrote:</span><br style=3D"caret-color: = rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: = normal; font-variant-caps: normal; font-weight: 400; letter-spacing: = normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: = none; white-space: normal; widows: 2; word-spacing: 0px; = -webkit-text-stroke-width: 0px; text-decoration-line: none; = text-decoration-thickness: auto; text-decoration-style: solid;"><br = style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: = 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; = letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; = text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; = -webkit-text-stroke-width: 0px; text-decoration-line: none; = text-decoration-thickness: auto; text-decoration-style: = solid;"><blockquote type=3D"cite" style=3D"font-family: Helvetica; = font-size: 12px; font-style: normal; font-variant-caps: normal; = font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; = text-indent: 0px; text-transform: none; white-space: normal; widows: 2; = word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-line: = none; text-decoration-thickness: auto; text-decoration-style: solid;">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=3D0.<br><br>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).<br><br>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."<br><br>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).<br><br>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.<br><br>Thanks,<br>Jeff<br>PS I notice via the archives that = there are occasional "New Contributors' Hour" meetings. Is the next one = scheduled yet?<br></blockquote><br style=3D"caret-color: rgb(0, 0, 0); = font-family: Helvetica; font-size: 12px; font-style: normal; = font-variant-caps: normal; font-weight: 400; letter-spacing: normal; = orphans: 2; text-align: start; text-indent: 0px; text-transform: none; = white-space: normal; widows: 2; word-spacing: 0px; = -webkit-text-stroke-width: 0px; text-decoration-line: none; = text-decoration-thickness: auto; text-decoration-style: solid;"><br = style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: = 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; = letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; = text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; = -webkit-text-stroke-width: 0px; text-decoration-line: none; = text-decoration-thickness: auto; text-decoration-style: solid;"><br = style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: = 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; = letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; = text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; = -webkit-text-stroke-width: 0px; text-decoration-line: none; = text-decoration-thickness: auto; text-decoration-style: solid;"><br = style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: = 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; = letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; = text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; = -webkit-text-stroke-width: 0px; text-decoration-line: none; = text-decoration-thickness: auto; text-decoration-style: solid;"><span = style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: = 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; = letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; = text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; = -webkit-text-stroke-width: 0px; text-decoration: none; float: none; = display: inline !important;">--<span = class=3D"Apple-converted-space"> </span></span><br = style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: = 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; = letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; = text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; = -webkit-text-stroke-width: 0px; text-decoration-line: none; = text-decoration-thickness: auto; text-decoration-style: solid;"><span = style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: = 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; = letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; = text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; = -webkit-text-stroke-width: 0px; text-decoration: none; float: none; = display: inline !important;">J=C3=A9r=C3=B4me Kieffer</span><br = style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: = 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; = letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; = text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; = -webkit-text-stroke-width: 0px; text-decoration-line: none; = text-decoration-thickness: auto; text-decoration-style: solid;"><span = style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: = 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; = letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; = text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; = -webkit-text-stroke-width: 0px; text-decoration: none; float: none; = display: inline !important;">tel +33 476 882 445</span><br = style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: = 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; = letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; = text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; = -webkit-text-stroke-width: 0px; text-decoration-line: none; = text-decoration-thickness: auto; text-decoration-style: solid;"><span = style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: = 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; = letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; = text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; = -webkit-text-stroke-width: 0px; text-decoration: none; float: none; = display: inline = !important;">_______________________________________________</span><br = style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: = 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; = letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; = text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; = -webkit-text-stroke-width: 0px; text-decoration-line: none; = text-decoration-thickness: auto; text-decoration-style: solid;"><span = style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: = 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; = letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; = text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; = -webkit-text-stroke-width: 0px; text-decoration: none; float: none; = display: inline !important;">NumPy-Discussion mailing list --<span = class=3D"Apple-converted-space"> </span></span><a = href=3D"mailto:[email protected]" style=3D"font-family: = Helvetica; font-size: 12px; font-style: normal; font-variant-caps: = normal; font-weight: 400; letter-spacing: normal; orphans: 2; = text-align: start; text-indent: 0px; text-transform: none; white-space: = normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: = 0px;">[email protected]</a><br style=3D"caret-color: rgb(0, 0, = 0); font-family: Helvetica; font-size: 12px; font-style: normal; = font-variant-caps: normal; font-weight: 400; letter-spacing: normal; = orphans: 2; text-align: start; text-indent: 0px; text-transform: none; = white-space: normal; widows: 2; word-spacing: 0px; = -webkit-text-stroke-width: 0px; text-decoration-line: none; = text-decoration-thickness: auto; text-decoration-style: solid;"><span = style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: = 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; = letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; = text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; = -webkit-text-stroke-width: 0px; text-decoration: none; float: none; = display: inline !important;">To unsubscribe send an email to<span = class=3D"Apple-converted-space"> </span></span><a = href=3D"mailto:[email protected]" style=3D"font-family: = Helvetica; font-size: 12px; font-style: normal; font-variant-caps: = normal; font-weight: 400; letter-spacing: normal; orphans: 2; = text-align: start; text-indent: 0px; text-transform: none; white-space: = normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: = 0px;">[email protected]</a><br style=3D"caret-color: = rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: = normal; font-variant-caps: normal; font-weight: 400; letter-spacing: = normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: = none; white-space: normal; widows: 2; word-spacing: 0px; = -webkit-text-stroke-width: 0px; text-decoration-line: none; = text-decoration-thickness: auto; text-decoration-style: solid;"><a = href=3D"https://mail.python.org/mailman3//lists/numpy-discussion.python.or= g" style=3D"font-family: Helvetica; font-size: 12px; font-style: normal; = font-variant-caps: normal; font-weight: 400; letter-spacing: normal; = orphans: 2; text-align: start; text-indent: 0px; text-transform: none; = white-space: normal; widows: 2; word-spacing: 0px; = -webkit-text-stroke-width: = 0px;">https://mail.python.org/mailman3//lists/numpy-discussion.python.org<= /a><br style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; = font-size: 12px; font-style: normal; font-variant-caps: normal; = font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; = text-indent: 0px; text-transform: none; white-space: normal; widows: 2; = word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-line: = none; text-decoration-thickness: auto; text-decoration-style: = solid;"><span style=3D"caret-color: rgb(0, 0, 0); font-family: = Helvetica; font-size: 12px; font-style: normal; font-variant-caps: = normal; font-weight: 400; letter-spacing: normal; orphans: 2; = text-align: start; text-indent: 0px; text-transform: none; white-space: = normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; = text-decoration: none; float: none; display: inline !important;">Member = address:<span class=3D"Apple-converted-space"> </span></span><a = href=3D"mailto:[email protected]" style=3D"font-family: Helvetica; = font-size: 12px; font-style: normal; font-variant-caps: normal; = font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; = text-indent: 0px; text-transform: none; white-space: normal; widows: 2; = word-spacing: 0px; -webkit-text-stroke-width: = 0px;">[email protected]</a></div></blockquote></div><br></div></div>= </body></html>= --Apple-Mail=_8F9D6D18-D614-4952-8001-CFBEC5422ADF-- --===============0677280979476835086== 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] --===============0677280979476835086==--