@stdlib/math-base-special-sinpif 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,177 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
package/NOTICE ADDED
@@ -0,0 +1 @@
1
+ Copyright (c) 2016-2026 The Stdlib Authors.
package/README.md ADDED
@@ -0,0 +1,276 @@
1
+ <!--
2
+
3
+ @license Apache-2.0
4
+
5
+ Copyright (c) 2025 The Stdlib Authors.
6
+
7
+ Licensed under the Apache License, Version 2.0 (the "License");
8
+ you may not use this file except in compliance with the License.
9
+ You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS,
15
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ See the License for the specific language governing permissions and
17
+ limitations under the License.
18
+
19
+ -->
20
+
21
+
22
+ <details>
23
+ <summary>
24
+ About stdlib...
25
+ </summary>
26
+ <p>We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.</p>
27
+ <p>The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.</p>
28
+ <p>When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.</p>
29
+ <p>To join us in bringing numerical computing to the web, get started by checking us out on <a href="https://github.com/stdlib-js/stdlib">GitHub</a>, and please consider <a href="https://opencollective.com/stdlib">financially supporting stdlib</a>. We greatly appreciate your continued support!</p>
30
+ </details>
31
+
32
+ # sinpif
33
+
34
+ [![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
35
+
36
+ > Compute the [sine][@stdlib/math/base/special/sinf] of a number times [π][@stdlib/constants/float32/pi].
37
+
38
+ <section class="installation">
39
+
40
+ ## Installation
41
+
42
+ ```bash
43
+ npm install @stdlib/math-base-special-sinpif
44
+ ```
45
+
46
+ </section>
47
+
48
+ <section class="usage">
49
+
50
+ ## Usage
51
+
52
+ ```javascript
53
+ var sinpif = require( '@stdlib/math-base-special-sinpif' );
54
+ ```
55
+
56
+ #### sinpif( x )
57
+
58
+ Computes `sin(πx)` in single-precision floating-point format more accurately than `sin(pi*x)`, especially for large `x`.
59
+
60
+ ```javascript
61
+ var y = sinpif( 0.0 );
62
+ // returns 0.0
63
+
64
+ y = sinpif( 0.5 );
65
+ // returns 1.0
66
+
67
+ y = sinpif( 0.9 );
68
+ // returns ~0.309
69
+
70
+ y = sinpif( NaN );
71
+ // returns NaN
72
+ ```
73
+
74
+ </section>
75
+
76
+ <!-- /.usage -->
77
+
78
+ <section class="examples">
79
+
80
+ ## Examples
81
+
82
+ <!-- eslint no-undef: "error" -->
83
+
84
+ ```javascript
85
+ var uniform = require( '@stdlib/random-array-uniform' );
86
+ var logEachMap = require( '@stdlib/console-log-each-map' );
87
+ var sinpif = require( '@stdlib/math-base-special-sinpif' );
88
+
89
+ var opts = {
90
+ 'dtype': 'float32'
91
+ };
92
+ var x = uniform( 100, -100.0, 100.0, opts );
93
+
94
+ logEachMap( 'sin( π * %0.4f ) = %0.4f', x, sinpif );
95
+ ```
96
+
97
+ </section>
98
+
99
+ <!-- /.examples -->
100
+
101
+ <!-- C interface documentation. -->
102
+
103
+ * * *
104
+
105
+ <section class="c">
106
+
107
+ ## C APIs
108
+
109
+ <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
110
+
111
+ <section class="intro">
112
+
113
+ </section>
114
+
115
+ <!-- /.intro -->
116
+
117
+ <!-- C usage documentation. -->
118
+
119
+ <section class="usage">
120
+
121
+ ### Usage
122
+
123
+ ```c
124
+ #include "stdlib/math/base/special/sinpif.h"
125
+ ```
126
+
127
+ #### stdlib_base_sinpif( x )
128
+
129
+ Computes `sin(πx)` in single-precision floating-point format more accurately than `sin(pi*x)`, especially for large `x`.
130
+
131
+ ```c
132
+ float y = stdlib_base_sinpif( 0.5f );
133
+ // returns 1.0f
134
+ ```
135
+
136
+ The function accepts the following arguments:
137
+
138
+ - **x**: `[in] float` input value.
139
+
140
+ ```c
141
+ float stdlib_base_sinpif( const float x );
142
+ ```
143
+
144
+ </section>
145
+
146
+ <!-- /.usage -->
147
+
148
+ <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
149
+
150
+ <section class="notes">
151
+
152
+ </section>
153
+
154
+ <!-- /.notes -->
155
+
156
+ <!-- C API usage examples. -->
157
+
158
+ <section class="examples">
159
+
160
+ ### Examples
161
+
162
+ ```c
163
+ #include "stdlib/math/base/special/sinpif.h"
164
+ #include <stdio.h>
165
+
166
+ int main( void ) {
167
+ const float x[] = { 0.0f, 0.523f, 0.785f, 1.047f, 3.14f };
168
+
169
+ float y;
170
+ int i;
171
+ for ( i = 0; i < 5; i++ ) {
172
+ y = stdlib_base_sinpif( x[ i ] );
173
+ printf( "sin( π * %f ) = %f\n", x[ i ], y );
174
+ }
175
+ }
176
+ ```
177
+
178
+ </section>
179
+
180
+ <!-- /.examples -->
181
+
182
+ </section>
183
+
184
+ <!-- /.c -->
185
+
186
+ <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
187
+
188
+ <section class="related">
189
+
190
+ </section>
191
+
192
+ <!-- /.related -->
193
+
194
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
195
+
196
+
197
+ <section class="main-repo" >
198
+
199
+ * * *
200
+
201
+ ## Notice
202
+
203
+ This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
204
+
205
+ For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib].
206
+
207
+ #### Community
208
+
209
+ [![Chat][chat-image]][chat-url]
210
+
211
+ ---
212
+
213
+ ## License
214
+
215
+ See [LICENSE][stdlib-license].
216
+
217
+
218
+ ## Copyright
219
+
220
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
221
+
222
+ </section>
223
+
224
+ <!-- /.stdlib -->
225
+
226
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
227
+
228
+ <section class="links">
229
+
230
+ [npm-image]: http://img.shields.io/npm/v/@stdlib/math-base-special-sinpif.svg
231
+ [npm-url]: https://npmjs.org/package/@stdlib/math-base-special-sinpif
232
+
233
+ [test-image]: https://github.com/stdlib-js/math-base-special-sinpif/actions/workflows/test.yml/badge.svg?branch=v0.1.0
234
+ [test-url]: https://github.com/stdlib-js/math-base-special-sinpif/actions/workflows/test.yml?query=branch:v0.1.0
235
+
236
+ [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/math-base-special-sinpif/main.svg
237
+ [coverage-url]: https://codecov.io/github/stdlib-js/math-base-special-sinpif?branch=main
238
+
239
+ <!--
240
+
241
+ [dependencies-image]: https://img.shields.io/david/stdlib-js/math-base-special-sinpif.svg
242
+ [dependencies-url]: https://david-dm.org/stdlib-js/math-base-special-sinpif/main
243
+
244
+ -->
245
+
246
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
247
+ [chat-url]: https://stdlib.zulipchat.com
248
+
249
+ [stdlib]: https://github.com/stdlib-js/stdlib
250
+
251
+ [stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
252
+
253
+ [umd]: https://github.com/umdjs/umd
254
+ [es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
255
+
256
+ [deno-url]: https://github.com/stdlib-js/math-base-special-sinpif/tree/deno
257
+ [deno-readme]: https://github.com/stdlib-js/math-base-special-sinpif/blob/deno/README.md
258
+ [umd-url]: https://github.com/stdlib-js/math-base-special-sinpif/tree/umd
259
+ [umd-readme]: https://github.com/stdlib-js/math-base-special-sinpif/blob/umd/README.md
260
+ [esm-url]: https://github.com/stdlib-js/math-base-special-sinpif/tree/esm
261
+ [esm-readme]: https://github.com/stdlib-js/math-base-special-sinpif/blob/esm/README.md
262
+ [branches-url]: https://github.com/stdlib-js/math-base-special-sinpif/blob/main/branches.md
263
+
264
+ [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/math-base-special-sinpif/main/LICENSE
265
+
266
+ [@stdlib/math/base/special/sinf]: https://www.npmjs.com/package/@stdlib/math-base-special-sinf
267
+
268
+ [@stdlib/constants/float32/pi]: https://www.npmjs.com/package/@stdlib/constants-float32-pi
269
+
270
+ <!-- <related-links> -->
271
+
272
+ <!-- </related-links> -->
273
+
274
+ </section>
275
+
276
+ <!-- /.links -->
package/SECURITY.md ADDED
@@ -0,0 +1,5 @@
1
+ # Security
2
+
3
+ > Policy for reporting security vulnerabilities.
4
+
5
+ See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security).
@@ -0,0 +1,3 @@
1
+ /// <reference path="../docs/types/index.d.ts" />
2
+ import sinpif from '../docs/types/index';
3
+ export = sinpif;
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";var M=function(i,f){return function(){return f||i((f={exports:{}}).exports,f),f.exports}};var D=M(function(b,l){
2
+ var O=require('@stdlib/math-base-special-kernel-cosf/dist'),t=require('@stdlib/math-base-special-kernel-sinf/dist'),H=require('@stdlib/math-base-special-copysignf/dist'),r=require('@stdlib/number-float64-base-to-float32/dist'),G=require('@stdlib/number-float32-base-to-uint32/dist'),q=require('@stdlib/number-float32-base-to-word/dist'),T=require('@stdlib/number-float32-base-from-word/dist'),n=require('@stdlib/constants-float32-sign-mask/dist'),K=require('@stdlib/constants-float32-abs-mask/dist'),P=require('@stdlib/constants-float32-exponent-mask/dist'),c=require('@stdlib/constants-float32-exponent-bias/dist'),p=require('@stdlib/constants-float32-num-significand-bits/dist'),x=require('@stdlib/constants-float32-significand-mask/dist'),_=require('@stdlib/constants-float64-pi/dist'),U=1065353216,E=1056964608,I=1048576e3,L=1061158912,B=947912704,C=1258291200,S=r(3.14160156),R=r(-890890988e-14),X=4294901760,d=255,o=r(8388608),h=r(11920928955078125e-23),F=r(0),N=r(.5),W=r(1);function k(i){var f,a,u,s,A,v,e;return i=r(i),f=q(r(i)),a=(f&K)>>>0,v=T(a),a<U?a<I?a<B?i===0?i:(u=T(f&X),u=r(u*o),s=r(r(i*o)-u),e=r(r(r(R+S)*s)+r(R*u)+r(S*u)),r(e*h)):(e=t(_*v),f&n?-e:e):(a<E?e=O(_*r(N-v)):a<L?e=O(_*r(v-N)):e=t(_*r(W-v)),f&n?-e:e):a<C?(A=(a>>p&d)-c,a&=~(x>>A),i=T(a),v=r(v-i),a=q(v),a===0?e=F:(a<E?a<I?e=t(_*v):e=O(_*r(N-v)):a<L?e=O(_*r(v-N)):e=t(_*r(W-v)),A=G(i),e=A&1?-e:e),f&n?-e:e):a>=P?NaN:H(F,i)}l.exports=k
3
+ });var m=D();module.exports=m;
4
+ /** @license Apache-2.0 */
5
+ /** @license Apache-2.0 */
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../lib/main.js", "../lib/index.js"],
4
+ "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*\n*\n* ## Notice\n*\n* The following copyright, license, and long comment were part of the original implementation available as part of [FreeBSD]{@link https://github.com/freebsd/freebsd-src/blob/main/lib/msun/src/s_sinpif.c}. The implementation follows the original, but has been modified for JavaScript.\n*\n* ```text\n* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\n*\n* Developed at SunPro, a Sun Microsystems, Inc. business.\n* Permission to use, copy, modify, and distribute this\n* software is freely granted, provided that this notice\n* is preserved.\n* ```\n*/\n\n'use strict';\n\n// MODULES //\n\nvar kernelCosf = require( '@stdlib/math-base-special-kernel-cosf' );\nvar kernelSinf = require( '@stdlib/math-base-special-kernel-sinf' );\nvar copysignf = require( '@stdlib/math-base-special-copysignf' );\nvar f32 = require( '@stdlib/number-float64-base-to-float32' );\nvar float32ToUint32 = require( '@stdlib/number-float32-base-to-uint32' );\nvar toWordf = require( '@stdlib/number-float32-base-to-word' );\nvar fromWordf = require( '@stdlib/number-float32-base-from-word' );\nvar FLOAT32_SIGN_MASK = require( '@stdlib/constants-float32-sign-mask' );\nvar FLOAT32_ABS_MASK = require( '@stdlib/constants-float32-abs-mask' );\nvar FLOAT32_EXPONENT_MASK = require( '@stdlib/constants-float32-exponent-mask' );\nvar FLOAT32_EXPONENT_BIAS = require( '@stdlib/constants-float32-exponent-bias' );\nvar FLOAT32_NUM_SIGNIFICAND_BITS = require( '@stdlib/constants-float32-num-significand-bits' );\nvar FLOAT32_SIGNIFICAND_MASK = require( '@stdlib/constants-float32-significand-mask' );\nvar PI = require( '@stdlib/constants-float64-pi' );\n\n\n// VARIABLES //\n\n// 1 => 0 01111111 00000000000000000000000 => 0x3f800000 = 1065353216\nvar ONE_WORD = 0x3f800000 >>> 0; // asm type annotation\n\n// 1/2 = 0.5 => 0 01111110 00000000000000000000000 => 0x3f000000 = 1056964608\nvar HALF_WORD = 0x3f000000 >>> 0; // asm type annotation\n\n// 1/4 = 0.25 => 0 01111101 00000000000000000000000 => 0x3e800000 = 1048576000\nvar QUARTER_WORD = 0x3e800000 >>> 0; // asm type annotation\n\n// 3/4 = 0.75 => 0 01111110 10000000000000000000000 => 0x3f400000 = 1061158912\nvar THREE_QUARTER_WORD = 0x3f400000 >>> 0; // asm type annotation\n\n// 2^-14 = 0.00006103515625 => 0 01110001 00000000000000000000000 => 0x38800000 = 947912704\nvar SMALL_WORD = 0x38800000 >>> 0; // asm type annotation\n\n// 2^23 = 8388608 => 0 10010110 00000000000000000000000 => 0x4b000000 = 1258291200\nvar LARGE_WORD = 0x4b000000 >>> 0; // asm type annotation\n\n// High and low parts of \u03C0 in single-precision floating-point format:\nvar PI_HIGH = f32( 3.14160156 ); // 0x40491000\nvar PI_LOW = f32( -8.90890988e-6 ); // 0xb715777a\n\n// Mask for extracting the high 16 bits of a 32-bit integer:\nvar HIGH_16_MASK = 0xffff0000 >>> 0; // asm type annotation\n\n// Mask for extracting the exponent bits of a 32-bit float:\nvar FLOAT32_EXPONENT_FIELD_MASK = 0xff >>> 0; // asm type annotation\n\nvar TWO_23 = f32( 8388608 ); // 2^23\nvar TWO_N23 = f32( 1.1920928955078125e-7 ); // 2^-23\n\nvar ZERO = f32( 0.0 );\nvar HALF = f32( 0.5 );\nvar ONE = f32( 1.0 );\n\n\n// MAIN //\n\n/**\n* Computes the value of `sin(\u03C0x)` in single-precision floating-point format.\n*\n* ## Notes\n*\n* - The function computes `sin(\u03C0x)` more accurately than the obvious approach, especially for large `x`.\n*\n* @param {number} x - input value\n* @returns {number} function value\n*\n* @example\n* var y = sinpif( 0.0 );\n* // returns 0.0\n*\n* @example\n* var y = sinpif( 0.5 );\n* // returns 1.0\n*\n* @example\n* var y = sinpif( 0.9 );\n* // returns ~0.309\n*\n* @example\n* var y = sinpif( NaN );\n* // returns NaN\n*/\nfunction sinpif( x ) {\n\tvar hx;\n\tvar ix;\n\tvar hi;\n\tvar lo;\n\tvar j0;\n\tvar ax;\n\tvar s;\n\n\tx = f32( x );\n\thx = toWordf( f32( x ) );\n\tix = (hx & FLOAT32_ABS_MASK) >>> 0; // asm type annotation\n\tax = fromWordf( ix ); // asm type annotation\n\n\t// Case: |x| < 1\n\tif ( ix < ONE_WORD ) {\n\t\t// Case: |x| < 0.25\n\t\tif ( ix < QUARTER_WORD ) {\n\t\t\t// Case: |x| < 2^-14\n\t\t\tif ( ix < SMALL_WORD ) {\n\t\t\t\tif ( x === 0.0 ) {\n\t\t\t\t\treturn x;\n\t\t\t\t}\n\t\t\t\thi = fromWordf( hx & HIGH_16_MASK );\n\t\t\t\thi = f32( hi * TWO_23 );\n\t\t\t\tlo = f32( f32( x * TWO_23 ) - hi );\n\n\t\t\t\t// eslint-disable-next-line max-len\n\t\t\t\ts = f32( f32( f32( PI_LOW+PI_HIGH )*lo ) + f32( PI_LOW*hi ) + f32( PI_HIGH*hi ) );\n\t\t\t\treturn f32( s * TWO_N23 );\n\t\t\t}\n\t\t\ts = kernelSinf( PI * ax );\n\t\t\treturn ( hx & FLOAT32_SIGN_MASK ) ? -s : s;\n\t\t}\n\t\t// Case: |x| < 0.5\n\t\tif ( ix < HALF_WORD ) {\n\t\t\ts = kernelCosf( PI * f32( HALF - ax ) );\n\t\t} else if ( ix < THREE_QUARTER_WORD ) { // Case: |x| < 0.75\n\t\t\ts = kernelCosf( PI * f32( ax - HALF ) );\n\t\t} else {\n\t\t\ts = kernelSinf( PI * f32( ONE - ax ) );\n\t\t}\n\t\treturn ( hx & FLOAT32_SIGN_MASK ) ? -s : s;\n\t}\n\t// Case: 1 <= |x| < 2^23\n\tif ( ix < LARGE_WORD ) {\n\t\t// Fast floor by bitwise manipulation:\n\t\tj0 = ( ( ix >> FLOAT32_NUM_SIGNIFICAND_BITS ) & FLOAT32_EXPONENT_FIELD_MASK ) - FLOAT32_EXPONENT_BIAS; // eslint-disable-line max-len\n\t\tix &= ~( FLOAT32_SIGNIFICAND_MASK >> j0 );\n\t\tx = fromWordf( ix );\n\n\t\tax = f32( ax - x );\n\t\tix = toWordf( ax );\n\t\tif ( ix === 0 ) {\n\t\t\ts = ZERO;\n\t\t} else {\n\t\t\t// Case: |x| < 0.5\n\t\t\tif ( ix < HALF_WORD ) {\n\t\t\t\t// Case: |x| < 0.25\n\t\t\t\tif ( ix < QUARTER_WORD ) {\n\t\t\t\t\ts = kernelSinf( PI * ax );\n\t\t\t\t} else {\n\t\t\t\t\ts = kernelCosf( PI * f32( HALF - ax ) );\n\t\t\t\t}\n\t\t\t} else if ( ix < THREE_QUARTER_WORD ) { // Case: |x| < 0.75\n\t\t\t\ts = kernelCosf( PI * f32( ax - HALF ) );\n\t\t\t} else {\n\t\t\t\ts = kernelSinf( PI * f32( ONE - ax ) );\n\t\t\t}\n\t\t\tj0 = float32ToUint32( x );\n\t\t\ts = ( j0 & 1 ) ? -s : s;\n\t\t}\n\t\treturn ( hx & FLOAT32_SIGN_MASK ) ? -s : s;\n\t}\n\t// Case: x is NaN or infinity\n\tif ( ix >= FLOAT32_EXPONENT_MASK ) {\n\t\treturn NaN;\n\t}\n\t// Case: |x| >= 2^23 is always an integer, so return +-0.\n\treturn copysignf( ZERO, x );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sinpif;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Compute the value of `sin(\u03C0x)` in single-precision floating-point format.\n*\n* @module @stdlib/math-base-special-sinpif\n*\n* @example\n* var sinpif = require( '@stdlib/math-base-special-sinpif' );\n*\n* var y = sinpif( 0.0 );\n* // returns 0.0\n*\n* y = sinpif( 0.5 );\n* // returns 1.0\n*\n* y = sinpif( 0.9 );\n* // returns ~0.309\n*\n* y = sinpif( NaN );\n* // returns NaN\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
5
+ "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAoCA,IAAIC,EAAa,QAAS,uCAAwC,EAC9DC,EAAa,QAAS,uCAAwC,EAC9DC,EAAY,QAAS,qCAAsC,EAC3DC,EAAM,QAAS,wCAAyC,EACxDC,EAAkB,QAAS,uCAAwC,EACnEC,EAAU,QAAS,qCAAsC,EACzDC,EAAY,QAAS,uCAAwC,EAC7DC,EAAoB,QAAS,qCAAsC,EACnEC,EAAmB,QAAS,oCAAqC,EACjEC,EAAwB,QAAS,yCAA0C,EAC3EC,EAAwB,QAAS,yCAA0C,EAC3EC,EAA+B,QAAS,gDAAiD,EACzFC,EAA2B,QAAS,4CAA6C,EACjFC,EAAK,QAAS,8BAA+B,EAM7CC,EAAW,WAGXC,EAAY,WAGZC,EAAe,UAGfC,EAAqB,WAGrBC,EAAa,UAGbC,EAAa,WAGbC,EAAUjB,EAAK,UAAW,EAC1BkB,EAASlB,EAAK,cAAe,EAG7BmB,EAAe,WAGfC,EAA8B,IAE9BC,EAASrB,EAAK,OAAQ,EACtBsB,EAAUtB,EAAK,qBAAsB,EAErCuB,EAAOvB,EAAK,CAAI,EAChBwB,EAAOxB,EAAK,EAAI,EAChByB,EAAMzB,EAAK,CAAI,EA+BnB,SAAS0B,EAAQC,EAAI,CACpB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,OANAP,EAAI3B,EAAK2B,CAAE,EACXC,EAAK1B,EAASF,EAAK2B,CAAE,CAAE,EACvBE,GAAMD,EAAKvB,KAAsB,EACjC4B,EAAK9B,EAAW0B,CAAG,EAGdA,EAAKlB,EAEJkB,EAAKhB,EAEJgB,EAAKd,EACJY,IAAM,EACHA,GAERG,EAAK3B,EAAWyB,EAAKT,CAAa,EAClCW,EAAK9B,EAAK8B,EAAKT,CAAO,EACtBU,EAAK/B,EAAKA,EAAK2B,EAAIN,CAAO,EAAIS,CAAG,EAGjCI,EAAIlC,EAAKA,EAAKA,EAAKkB,EAAOD,CAAQ,EAAEc,CAAG,EAAI/B,EAAKkB,EAAOY,CAAG,EAAI9B,EAAKiB,EAAQa,CAAG,CAAE,EACzE9B,EAAKkC,EAAIZ,CAAQ,IAEzBY,EAAIpC,EAAYY,EAAKuB,CAAG,EACfL,EAAKxB,EAAsB,CAAC8B,EAAIA,IAGrCL,EAAKjB,EACTsB,EAAIrC,EAAYa,EAAKV,EAAKwB,EAAOS,CAAG,CAAE,EAC3BJ,EAAKf,EAChBoB,EAAIrC,EAAYa,EAAKV,EAAKiC,EAAKT,CAAK,CAAE,EAEtCU,EAAIpC,EAAYY,EAAKV,EAAKyB,EAAMQ,CAAG,CAAE,EAE7BL,EAAKxB,EAAsB,CAAC8B,EAAIA,GAGrCL,EAAKb,GAETgB,GAASH,GAAMrB,EAAiCY,GAAgCb,EAChFsB,GAAM,EAAGpB,GAA4BuB,GACrCL,EAAIxB,EAAW0B,CAAG,EAElBI,EAAKjC,EAAKiC,EAAKN,CAAE,EACjBE,EAAK3B,EAAS+B,CAAG,EACZJ,IAAO,EACXK,EAAIX,GAGCM,EAAKjB,EAEJiB,EAAKhB,EACTqB,EAAIpC,EAAYY,EAAKuB,CAAG,EAExBC,EAAIrC,EAAYa,EAAKV,EAAKwB,EAAOS,CAAG,CAAE,EAE5BJ,EAAKf,EAChBoB,EAAIrC,EAAYa,EAAKV,EAAKiC,EAAKT,CAAK,CAAE,EAEtCU,EAAIpC,EAAYY,EAAKV,EAAKyB,EAAMQ,CAAG,CAAE,EAEtCD,EAAK/B,EAAiB0B,CAAE,EACxBO,EAAMF,EAAK,EAAM,CAACE,EAAIA,GAEdN,EAAKxB,EAAsB,CAAC8B,EAAIA,GAGrCL,GAAMvB,EACH,IAGDP,EAAWwB,EAAMI,CAAE,CAC3B,CAKA/B,EAAO,QAAU8B,IChKjB,IAAIS,EAAO,IAKX,OAAO,QAAUA",
6
+ "names": ["require_main", "__commonJSMin", "exports", "module", "kernelCosf", "kernelSinf", "copysignf", "f32", "float32ToUint32", "toWordf", "fromWordf", "FLOAT32_SIGN_MASK", "FLOAT32_ABS_MASK", "FLOAT32_EXPONENT_MASK", "FLOAT32_EXPONENT_BIAS", "FLOAT32_NUM_SIGNIFICAND_BITS", "FLOAT32_SIGNIFICAND_MASK", "PI", "ONE_WORD", "HALF_WORD", "QUARTER_WORD", "THREE_QUARTER_WORD", "SMALL_WORD", "LARGE_WORD", "PI_HIGH", "PI_LOW", "HIGH_16_MASK", "FLOAT32_EXPONENT_FIELD_MASK", "TWO_23", "TWO_N23", "ZERO", "HALF", "ONE", "sinpif", "x", "hx", "ix", "hi", "lo", "j0", "ax", "s", "main"]
7
+ }
@@ -0,0 +1,52 @@
1
+ /*
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2025 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ // TypeScript Version: 4.1
20
+
21
+ /**
22
+ * Computes the value of `sin(πx)` in single-precision floating-point format.
23
+ *
24
+ * ## Notes
25
+ *
26
+ * - The function computes `sin(πx)` more accurately than the obvious approach, especially for large `x`.
27
+ *
28
+ * @param x - input value
29
+ * @returns function value
30
+ *
31
+ * @example
32
+ * var y = sinpif( 0.0 );
33
+ * // returns 0.0
34
+ *
35
+ * @example
36
+ * var y = sinpif( 0.5 );
37
+ * // returns 1.0
38
+ *
39
+ * @example
40
+ * var y = sinpif( 0.9 );
41
+ * // returns ~0.309
42
+ *
43
+ * @example
44
+ * var y = sinpif( NaN );
45
+ * // returns NaN
46
+ */
47
+ declare function sinpif( x: number ): number;
48
+
49
+
50
+ // EXPORTS //
51
+
52
+ export = sinpif;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2025 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ #ifndef STDLIB_MATH_BASE_SPECIAL_SINPIF_H
20
+ #define STDLIB_MATH_BASE_SPECIAL_SINPIF_H
21
+
22
+ /*
23
+ * If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
24
+ */
25
+ #ifdef __cplusplus
26
+ extern "C" {
27
+ #endif
28
+
29
+ /**
30
+ * Computes the value of `sin(πx)` in single-precision floating-point format.
31
+ */
32
+ float stdlib_base_sinpif( const float x );
33
+
34
+ #ifdef __cplusplus
35
+ }
36
+ #endif
37
+
38
+ #endif // !STDLIB_MATH_BASE_SPECIAL_SINPIF_H
package/lib/index.js ADDED
@@ -0,0 +1,49 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2025 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ /**
22
+ * Compute the value of `sin(πx)` in single-precision floating-point format.
23
+ *
24
+ * @module @stdlib/math-base-special-sinpif
25
+ *
26
+ * @example
27
+ * var sinpif = require( '@stdlib/math-base-special-sinpif' );
28
+ *
29
+ * var y = sinpif( 0.0 );
30
+ * // returns 0.0
31
+ *
32
+ * y = sinpif( 0.5 );
33
+ * // returns 1.0
34
+ *
35
+ * y = sinpif( 0.9 );
36
+ * // returns ~0.309
37
+ *
38
+ * y = sinpif( NaN );
39
+ * // returns NaN
40
+ */
41
+
42
+ // MODULES //
43
+
44
+ var main = require( './main.js' );
45
+
46
+
47
+ // EXPORTS //
48
+
49
+ module.exports = main;
package/lib/main.js ADDED
@@ -0,0 +1,204 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2025 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ *
18
+ *
19
+ * ## Notice
20
+ *
21
+ * The following copyright, license, and long comment were part of the original implementation available as part of [FreeBSD]{@link https://github.com/freebsd/freebsd-src/blob/main/lib/msun/src/s_sinpif.c}. The implementation follows the original, but has been modified for JavaScript.
22
+ *
23
+ * ```text
24
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
25
+ *
26
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
27
+ * Permission to use, copy, modify, and distribute this
28
+ * software is freely granted, provided that this notice
29
+ * is preserved.
30
+ * ```
31
+ */
32
+
33
+ 'use strict';
34
+
35
+ // MODULES //
36
+
37
+ var kernelCosf = require( '@stdlib/math-base-special-kernel-cosf' );
38
+ var kernelSinf = require( '@stdlib/math-base-special-kernel-sinf' );
39
+ var copysignf = require( '@stdlib/math-base-special-copysignf' );
40
+ var f32 = require( '@stdlib/number-float64-base-to-float32' );
41
+ var float32ToUint32 = require( '@stdlib/number-float32-base-to-uint32' );
42
+ var toWordf = require( '@stdlib/number-float32-base-to-word' );
43
+ var fromWordf = require( '@stdlib/number-float32-base-from-word' );
44
+ var FLOAT32_SIGN_MASK = require( '@stdlib/constants-float32-sign-mask' );
45
+ var FLOAT32_ABS_MASK = require( '@stdlib/constants-float32-abs-mask' );
46
+ var FLOAT32_EXPONENT_MASK = require( '@stdlib/constants-float32-exponent-mask' );
47
+ var FLOAT32_EXPONENT_BIAS = require( '@stdlib/constants-float32-exponent-bias' );
48
+ var FLOAT32_NUM_SIGNIFICAND_BITS = require( '@stdlib/constants-float32-num-significand-bits' );
49
+ var FLOAT32_SIGNIFICAND_MASK = require( '@stdlib/constants-float32-significand-mask' );
50
+ var PI = require( '@stdlib/constants-float64-pi' );
51
+
52
+
53
+ // VARIABLES //
54
+
55
+ // 1 => 0 01111111 00000000000000000000000 => 0x3f800000 = 1065353216
56
+ var ONE_WORD = 0x3f800000 >>> 0; // asm type annotation
57
+
58
+ // 1/2 = 0.5 => 0 01111110 00000000000000000000000 => 0x3f000000 = 1056964608
59
+ var HALF_WORD = 0x3f000000 >>> 0; // asm type annotation
60
+
61
+ // 1/4 = 0.25 => 0 01111101 00000000000000000000000 => 0x3e800000 = 1048576000
62
+ var QUARTER_WORD = 0x3e800000 >>> 0; // asm type annotation
63
+
64
+ // 3/4 = 0.75 => 0 01111110 10000000000000000000000 => 0x3f400000 = 1061158912
65
+ var THREE_QUARTER_WORD = 0x3f400000 >>> 0; // asm type annotation
66
+
67
+ // 2^-14 = 0.00006103515625 => 0 01110001 00000000000000000000000 => 0x38800000 = 947912704
68
+ var SMALL_WORD = 0x38800000 >>> 0; // asm type annotation
69
+
70
+ // 2^23 = 8388608 => 0 10010110 00000000000000000000000 => 0x4b000000 = 1258291200
71
+ var LARGE_WORD = 0x4b000000 >>> 0; // asm type annotation
72
+
73
+ // High and low parts of π in single-precision floating-point format:
74
+ var PI_HIGH = f32( 3.14160156 ); // 0x40491000
75
+ var PI_LOW = f32( -8.90890988e-6 ); // 0xb715777a
76
+
77
+ // Mask for extracting the high 16 bits of a 32-bit integer:
78
+ var HIGH_16_MASK = 0xffff0000 >>> 0; // asm type annotation
79
+
80
+ // Mask for extracting the exponent bits of a 32-bit float:
81
+ var FLOAT32_EXPONENT_FIELD_MASK = 0xff >>> 0; // asm type annotation
82
+
83
+ var TWO_23 = f32( 8388608 ); // 2^23
84
+ var TWO_N23 = f32( 1.1920928955078125e-7 ); // 2^-23
85
+
86
+ var ZERO = f32( 0.0 );
87
+ var HALF = f32( 0.5 );
88
+ var ONE = f32( 1.0 );
89
+
90
+
91
+ // MAIN //
92
+
93
+ /**
94
+ * Computes the value of `sin(πx)` in single-precision floating-point format.
95
+ *
96
+ * ## Notes
97
+ *
98
+ * - The function computes `sin(πx)` more accurately than the obvious approach, especially for large `x`.
99
+ *
100
+ * @param {number} x - input value
101
+ * @returns {number} function value
102
+ *
103
+ * @example
104
+ * var y = sinpif( 0.0 );
105
+ * // returns 0.0
106
+ *
107
+ * @example
108
+ * var y = sinpif( 0.5 );
109
+ * // returns 1.0
110
+ *
111
+ * @example
112
+ * var y = sinpif( 0.9 );
113
+ * // returns ~0.309
114
+ *
115
+ * @example
116
+ * var y = sinpif( NaN );
117
+ * // returns NaN
118
+ */
119
+ function sinpif( x ) {
120
+ var hx;
121
+ var ix;
122
+ var hi;
123
+ var lo;
124
+ var j0;
125
+ var ax;
126
+ var s;
127
+
128
+ x = f32( x );
129
+ hx = toWordf( f32( x ) );
130
+ ix = (hx & FLOAT32_ABS_MASK) >>> 0; // asm type annotation
131
+ ax = fromWordf( ix ); // asm type annotation
132
+
133
+ // Case: |x| < 1
134
+ if ( ix < ONE_WORD ) {
135
+ // Case: |x| < 0.25
136
+ if ( ix < QUARTER_WORD ) {
137
+ // Case: |x| < 2^-14
138
+ if ( ix < SMALL_WORD ) {
139
+ if ( x === 0.0 ) {
140
+ return x;
141
+ }
142
+ hi = fromWordf( hx & HIGH_16_MASK );
143
+ hi = f32( hi * TWO_23 );
144
+ lo = f32( f32( x * TWO_23 ) - hi );
145
+
146
+ // eslint-disable-next-line max-len
147
+ s = f32( f32( f32( PI_LOW+PI_HIGH )*lo ) + f32( PI_LOW*hi ) + f32( PI_HIGH*hi ) );
148
+ return f32( s * TWO_N23 );
149
+ }
150
+ s = kernelSinf( PI * ax );
151
+ return ( hx & FLOAT32_SIGN_MASK ) ? -s : s;
152
+ }
153
+ // Case: |x| < 0.5
154
+ if ( ix < HALF_WORD ) {
155
+ s = kernelCosf( PI * f32( HALF - ax ) );
156
+ } else if ( ix < THREE_QUARTER_WORD ) { // Case: |x| < 0.75
157
+ s = kernelCosf( PI * f32( ax - HALF ) );
158
+ } else {
159
+ s = kernelSinf( PI * f32( ONE - ax ) );
160
+ }
161
+ return ( hx & FLOAT32_SIGN_MASK ) ? -s : s;
162
+ }
163
+ // Case: 1 <= |x| < 2^23
164
+ if ( ix < LARGE_WORD ) {
165
+ // Fast floor by bitwise manipulation:
166
+ j0 = ( ( ix >> FLOAT32_NUM_SIGNIFICAND_BITS ) & FLOAT32_EXPONENT_FIELD_MASK ) - FLOAT32_EXPONENT_BIAS; // eslint-disable-line max-len
167
+ ix &= ~( FLOAT32_SIGNIFICAND_MASK >> j0 );
168
+ x = fromWordf( ix );
169
+
170
+ ax = f32( ax - x );
171
+ ix = toWordf( ax );
172
+ if ( ix === 0 ) {
173
+ s = ZERO;
174
+ } else {
175
+ // Case: |x| < 0.5
176
+ if ( ix < HALF_WORD ) {
177
+ // Case: |x| < 0.25
178
+ if ( ix < QUARTER_WORD ) {
179
+ s = kernelSinf( PI * ax );
180
+ } else {
181
+ s = kernelCosf( PI * f32( HALF - ax ) );
182
+ }
183
+ } else if ( ix < THREE_QUARTER_WORD ) { // Case: |x| < 0.75
184
+ s = kernelCosf( PI * f32( ax - HALF ) );
185
+ } else {
186
+ s = kernelSinf( PI * f32( ONE - ax ) );
187
+ }
188
+ j0 = float32ToUint32( x );
189
+ s = ( j0 & 1 ) ? -s : s;
190
+ }
191
+ return ( hx & FLOAT32_SIGN_MASK ) ? -s : s;
192
+ }
193
+ // Case: x is NaN or infinity
194
+ if ( ix >= FLOAT32_EXPONENT_MASK ) {
195
+ return NaN;
196
+ }
197
+ // Case: |x| >= 2^23 is always an integer, so return +-0.
198
+ return copysignf( ZERO, x );
199
+ }
200
+
201
+
202
+ // EXPORTS //
203
+
204
+ module.exports = sinpif;
package/lib/native.js ADDED
@@ -0,0 +1,58 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2025 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var addon = require( './../src/addon.node' );
24
+
25
+
26
+ // MAIN //
27
+
28
+ /**
29
+ * Computes the value of `sin(πx)` in single-precision floating-point format.
30
+ *
31
+ * @private
32
+ * @param {number} x - input value
33
+ * @returns {number} function value
34
+ *
35
+ * @example
36
+ * var y = sinpif( 0.0 );
37
+ * // returns 0.0
38
+ *
39
+ * @example
40
+ * var y = sinpif( 0.5 );
41
+ * // returns 1.0
42
+ *
43
+ * @example
44
+ * var y = sinpif( 0.9 );
45
+ * // returns ~0.309
46
+ *
47
+ * @example
48
+ * var y = sinpif( NaN );
49
+ * // returns NaN
50
+ */
51
+ function sinpif( x ) {
52
+ return addon( x );
53
+ }
54
+
55
+
56
+ // EXPORTS //
57
+
58
+ module.exports = sinpif;
package/manifest.json ADDED
@@ -0,0 +1,111 @@
1
+ {
2
+ "options": {
3
+ "task": "build"
4
+ },
5
+ "fields": [
6
+ {
7
+ "field": "src",
8
+ "resolve": true,
9
+ "relative": true
10
+ },
11
+ {
12
+ "field": "include",
13
+ "resolve": true,
14
+ "relative": true
15
+ },
16
+ {
17
+ "field": "libraries",
18
+ "resolve": false,
19
+ "relative": false
20
+ },
21
+ {
22
+ "field": "libpath",
23
+ "resolve": true,
24
+ "relative": false
25
+ }
26
+ ],
27
+ "confs": [
28
+ {
29
+ "task": "build",
30
+ "src": [
31
+ "./src/main.c"
32
+ ],
33
+ "include": [
34
+ "./include"
35
+ ],
36
+ "libraries": [
37
+ "-lm"
38
+ ],
39
+ "libpath": [],
40
+ "dependencies": [
41
+ "@stdlib/math-base-napi-unary",
42
+ "@stdlib/number-float32-base-to-word",
43
+ "@stdlib/number-float32-base-from-word",
44
+ "@stdlib/math-base-special-kernel-cosf",
45
+ "@stdlib/math-base-special-kernel-sinf",
46
+ "@stdlib/math-base-special-copysignf",
47
+ "@stdlib/constants-float64-pi",
48
+ "@stdlib/constants-float32-abs-mask",
49
+ "@stdlib/constants-float32-sign-mask",
50
+ "@stdlib/constants-float32-exponent-mask",
51
+ "@stdlib/constants-float32-significand-mask",
52
+ "@stdlib/constants-float32-num-significand-bits",
53
+ "@stdlib/constants-float32-exponent-bias"
54
+ ]
55
+ },
56
+ {
57
+ "task": "benchmark",
58
+ "src": [
59
+ "./src/main.c"
60
+ ],
61
+ "include": [
62
+ "./include"
63
+ ],
64
+ "libraries": [
65
+ "-lm"
66
+ ],
67
+ "libpath": [],
68
+ "dependencies": [
69
+ "@stdlib/number-float32-base-to-word",
70
+ "@stdlib/number-float32-base-from-word",
71
+ "@stdlib/math-base-special-kernel-cosf",
72
+ "@stdlib/math-base-special-kernel-sinf",
73
+ "@stdlib/math-base-special-copysignf",
74
+ "@stdlib/constants-float64-pi",
75
+ "@stdlib/constants-float32-abs-mask",
76
+ "@stdlib/constants-float32-sign-mask",
77
+ "@stdlib/constants-float32-exponent-mask",
78
+ "@stdlib/constants-float32-significand-mask",
79
+ "@stdlib/constants-float32-num-significand-bits",
80
+ "@stdlib/constants-float32-exponent-bias"
81
+ ]
82
+ },
83
+ {
84
+ "task": "examples",
85
+ "src": [
86
+ "./src/main.c"
87
+ ],
88
+ "include": [
89
+ "./include"
90
+ ],
91
+ "libraries": [
92
+ "-lm"
93
+ ],
94
+ "libpath": [],
95
+ "dependencies": [
96
+ "@stdlib/number-float32-base-to-word",
97
+ "@stdlib/number-float32-base-from-word",
98
+ "@stdlib/math-base-special-kernel-cosf",
99
+ "@stdlib/math-base-special-kernel-sinf",
100
+ "@stdlib/math-base-special-copysignf",
101
+ "@stdlib/constants-float64-pi",
102
+ "@stdlib/constants-float32-abs-mask",
103
+ "@stdlib/constants-float32-sign-mask",
104
+ "@stdlib/constants-float32-exponent-mask",
105
+ "@stdlib/constants-float32-significand-mask",
106
+ "@stdlib/constants-float32-num-significand-bits",
107
+ "@stdlib/constants-float32-exponent-bias"
108
+ ]
109
+ }
110
+ ]
111
+ }
package/package.json ADDED
@@ -0,0 +1,88 @@
1
+ {
2
+ "name": "@stdlib/math-base-special-sinpif",
3
+ "version": "0.1.0",
4
+ "description": "Compute sin(πx) in single-precision floating-point format.",
5
+ "license": "Apache-2.0",
6
+ "author": {
7
+ "name": "The Stdlib Authors",
8
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
9
+ },
10
+ "contributors": [
11
+ {
12
+ "name": "The Stdlib Authors",
13
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
14
+ }
15
+ ],
16
+ "main": "./lib",
17
+ "gypfile": false,
18
+ "directories": {
19
+ "doc": "./docs",
20
+ "include": "./include",
21
+ "lib": "./lib",
22
+ "src": "./src",
23
+ "dist": "./dist"
24
+ },
25
+ "types": "./docs/types",
26
+ "scripts": {},
27
+ "homepage": "https://stdlib.io",
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git://github.com/stdlib-js/math-base-special-sinpif.git"
31
+ },
32
+ "bugs": {
33
+ "url": "https://github.com/stdlib-js/stdlib/issues"
34
+ },
35
+ "dependencies": {
36
+ "@stdlib/constants-float32-abs-mask": "^0.2.2",
37
+ "@stdlib/constants-float32-exponent-bias": "^0.2.2",
38
+ "@stdlib/constants-float32-exponent-mask": "^0.2.2",
39
+ "@stdlib/constants-float32-num-significand-bits": "^0.1.0",
40
+ "@stdlib/constants-float32-sign-mask": "^0.2.2",
41
+ "@stdlib/constants-float32-significand-mask": "^0.2.3",
42
+ "@stdlib/constants-float64-pi": "^0.2.2",
43
+ "@stdlib/math-base-napi-unary": "^0.2.5",
44
+ "@stdlib/math-base-special-copysignf": "^0.2.2",
45
+ "@stdlib/math-base-special-kernel-cosf": "github:stdlib-js/math-base-special-kernel-cosf#main",
46
+ "@stdlib/math-base-special-kernel-sinf": "github:stdlib-js/math-base-special-kernel-sinf#main",
47
+ "@stdlib/number-float32-base-from-word": "^0.2.2",
48
+ "@stdlib/number-float32-base-to-uint32": "^0.2.2",
49
+ "@stdlib/number-float32-base-to-word": "^0.2.2",
50
+ "@stdlib/number-float64-base-to-float32": "^0.2.2",
51
+ "@stdlib/utils-library-manifest": "^0.2.3"
52
+ },
53
+ "devDependencies": {},
54
+ "engines": {
55
+ "node": ">=0.10.0",
56
+ "npm": ">2.7.0"
57
+ },
58
+ "os": [
59
+ "aix",
60
+ "darwin",
61
+ "freebsd",
62
+ "linux",
63
+ "macos",
64
+ "openbsd",
65
+ "sunos",
66
+ "win32",
67
+ "windows"
68
+ ],
69
+ "keywords": [
70
+ "stdlib",
71
+ "stdmath",
72
+ "mathematics",
73
+ "math",
74
+ "math.sin",
75
+ "sin",
76
+ "sine",
77
+ "sinpif",
78
+ "pi",
79
+ "trig",
80
+ "trigonometry",
81
+ "radians",
82
+ "angle"
83
+ ],
84
+ "funding": {
85
+ "type": "opencollective",
86
+ "url": "https://opencollective.com/stdlib"
87
+ }
88
+ }
package/src/addon.c ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2025 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ #include "stdlib/math/base/special/sinpif.h"
20
+ #include "stdlib/math/base/napi/unary.h"
21
+
22
+ STDLIB_MATH_BASE_NAPI_MODULE_F_F( stdlib_base_sinpif )
package/src/main.c ADDED
@@ -0,0 +1,170 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2025 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ *
18
+ *
19
+ * ## Notice
20
+ *
21
+ * The following copyright, license, and long comment were part of the original implementation available as part of [FreeBSD]{@link https://github.com/freebsd/freebsd-src/blob/main/lib/msun/src/s_sinpif.c}. The implementation follows the original, but has been modified according to stdlib conventions.
22
+ *
23
+ * ```text
24
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
25
+ *
26
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
27
+ * Permission to use, copy, modify, and distribute this
28
+ * software is freely granted, provided that this notice
29
+ * is preserved.
30
+ * ```
31
+ */
32
+
33
+ #include "stdlib/math/base/special/sinpif.h"
34
+ #include "stdlib/number/float32/base/to_word.h"
35
+ #include "stdlib/number/float32/base/from_word.h"
36
+ #include "stdlib/math/base/special/kernel_cosf.h"
37
+ #include "stdlib/math/base/special/kernel_sinf.h"
38
+ #include "stdlib/math/base/special/copysignf.h"
39
+ #include "stdlib/constants/float64/pi.h"
40
+ #include "stdlib/constants/float32/abs_mask.h"
41
+ #include "stdlib/constants/float32/sign_mask.h"
42
+ #include "stdlib/constants/float32/exponent_mask.h"
43
+ #include "stdlib/constants/float32/significand_mask.h"
44
+ #include "stdlib/constants/float32/exponent_bias.h"
45
+ #include "stdlib/constants/float32/num_significand_bits.h"
46
+ #include <stdint.h>
47
+
48
+ // 1 => 0 01111111 00000000000000000000000 => 0x3f800000 = 1065353216
49
+ static const uint32_t ONE_WORD = 0x3f800000;
50
+
51
+ // 1/2 = 0.5 => 0 01111110 00000000000000000000000 => 0x3f000000 = 1056964608
52
+ static const uint32_t HALF_WORD = 0x3f000000;
53
+
54
+ // 1/4 = 0.25 => 0 01111101 00000000000000000000000 => 0x3e800000 = 1048576000
55
+ static const uint32_t QUARTER_WORD = 0x3e800000;
56
+
57
+ // 3/4 = 0.75 => 0 01111110 10000000000000000000000 => 0x3f400000 = 1061158912
58
+ static const uint32_t THREE_QUARTER_WORD = 0x3f400000;
59
+
60
+ // 2^-14 = 0.00006103515625 => 0 01110001 00000000000000000000000 => 0x38800000 = 947912704
61
+ static const uint32_t SMALL_WORD = 0x38800000;
62
+
63
+ // 2^23 = 8388608 => 0 10010110 00000000000000000000000 => 0x4b000000 = 1258291200
64
+ static const uint32_t LARGE_WORD = 0x4b000000;
65
+
66
+ // High and low parts of π in single-precision floating-point format:
67
+ static const float PI_HIGH = 3.14160156f; // 0x40491000
68
+ static const float PI_LOW = -8.90890988e-6f; // 0xb715777a
69
+
70
+ // Mask for extracting the high 16 bits of a 32-bit integer:
71
+ static const uint32_t HIGH_16_MASK = 0xffff0000;
72
+
73
+ // Mask for extracting the exponent bits of a 32-bit float:
74
+ static const uint32_t FLOAT32_EXPONENT_FIELD_MASK = 0xff;
75
+
76
+ static const float TWO_23 = 8388608.0f; // 2^23
77
+ static const float TWO_N23 = 1.1920928955078125e-7f; // 2^-23
78
+
79
+ /**
80
+ * Computes the value of `sin(πx)` in single-precision floating-point format.
81
+ *
82
+ * @param x input value (in radians)
83
+ * @return function value
84
+ *
85
+ * @example
86
+ * float y = stdlib_base_sinpif( 0.5f );
87
+ * // returns 1.0f
88
+ */
89
+ float stdlib_base_sinpif( const float x ) {
90
+ uint32_t hx;
91
+ uint32_t ix;
92
+ uint32_t j0;
93
+ float hi;
94
+ float lo;
95
+ float ax;
96
+ float fx;
97
+ float s;
98
+
99
+ stdlib_base_float32_to_word( x, &hx );
100
+ ix = hx & STDLIB_CONSTANT_FLOAT32_ABS_MASK;
101
+ stdlib_base_float32_from_word( ix, &ax );
102
+
103
+ // Case: |x| < 1
104
+ if ( ix < ONE_WORD ) {
105
+ // Case: |x| < 0.25
106
+ if ( ix < QUARTER_WORD ) {
107
+ // Case: |x| < 2^-14
108
+ if ( ix < SMALL_WORD ) {
109
+ if ( x == 0.0f ) {
110
+ return x;
111
+ }
112
+ stdlib_base_float32_from_word( hx & HIGH_16_MASK, &hi );
113
+ hi = hi * TWO_23;
114
+ lo = ( x * TWO_23 ) - hi;
115
+ s = ( PI_LOW+PI_HIGH )*lo + ( PI_LOW*hi ) + ( PI_HIGH*hi );
116
+ return s * TWO_N23;
117
+ }
118
+ s = stdlib_base_kernel_sinf( STDLIB_CONSTANT_FLOAT64_PI * (double)ax );
119
+ return ( hx & STDLIB_CONSTANT_FLOAT32_SIGN_MASK ) ? -s : s;
120
+ }
121
+ // Case: |x| < 0.5
122
+ if ( ix < HALF_WORD ) {
123
+ s = stdlib_base_kernel_cosf( STDLIB_CONSTANT_FLOAT64_PI * (double)(0.5f - ax) );
124
+ } else if ( ix < THREE_QUARTER_WORD ) { // Case: |x| < 0.75
125
+ s = stdlib_base_kernel_cosf( STDLIB_CONSTANT_FLOAT64_PI * (double)(ax - 0.5f) );
126
+ } else {
127
+ s = stdlib_base_kernel_sinf( STDLIB_CONSTANT_FLOAT64_PI * (double)(1.0f - ax) );
128
+ }
129
+ return ( hx & STDLIB_CONSTANT_FLOAT32_SIGN_MASK ) ? -s : s;
130
+ }
131
+ // Case: 1 <= |x| < 2^23
132
+ if ( ix < LARGE_WORD ) {
133
+ // Fast floor by bitwise manipulation:
134
+ j0 = ( ( ix >> STDLIB_CONSTANT_FLOAT32_NUM_SIGNIFICAND_BITS ) & FLOAT32_EXPONENT_FIELD_MASK ) - STDLIB_CONSTANT_FLOAT32_EXPONENT_BIAS;
135
+ ix &= ~( STDLIB_CONSTANT_FLOAT32_SIGNIFICAND_MASK >> j0 );
136
+ stdlib_base_float32_from_word( ix, &fx );
137
+
138
+ ax -= fx;
139
+ stdlib_base_float32_to_word( ax, &ix );
140
+ if ( ix == 0 ) {
141
+ s = 0.0f;
142
+ } else {
143
+ // Case: |x| < 0.5
144
+ if ( ix < HALF_WORD ) {
145
+ // Case: |x| < 0.25
146
+ if ( ix < QUARTER_WORD ) {
147
+ s = stdlib_base_kernel_sinf( STDLIB_CONSTANT_FLOAT64_PI * (double)ax );
148
+ } else {
149
+ s = stdlib_base_kernel_cosf( STDLIB_CONSTANT_FLOAT64_PI * (double)(0.5f - ax) );
150
+ }
151
+ } else {
152
+ // Case: |x| < 0.75
153
+ if ( ix < THREE_QUARTER_WORD ) {
154
+ s = stdlib_base_kernel_cosf( STDLIB_CONSTANT_FLOAT64_PI * (double)(ax - 0.5f) );
155
+ } else {
156
+ s = stdlib_base_kernel_sinf( STDLIB_CONSTANT_FLOAT64_PI * (double)(1.0f - ax) );
157
+ }
158
+ }
159
+ j0 = (uint32_t)fx;
160
+ s = ( j0 & 1 ) ? -s : s;
161
+ }
162
+ return ( hx & STDLIB_CONSTANT_FLOAT32_SIGN_MASK ) ? -s : s;
163
+ }
164
+ // Case: x is NaN or infinity
165
+ if ( ix >= STDLIB_CONSTANT_FLOAT32_EXPONENT_MASK ) {
166
+ return 0.0f / 0.0f; // NaN
167
+ }
168
+ // Case: |x| >= 2^23 is always an integer, so return +-0.
169
+ return stdlib_base_copysignf( 0.0f, x );
170
+ }