Skip to content

Commit a653e26

Browse files
committed
feat: temp commit
1 parent f3dfedc commit a653e26

File tree

34 files changed

+2581
-0
lines changed

34 files changed

+2581
-0
lines changed
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2018 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+
# sinpi
22+
23+
> Compute the [sine][@stdlib/math/base/special/sin] of a number times [π][@stdlib/constants/float64/pi].
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var sinpi = require( '@stdlib/math/base/special/sinpi' );
31+
```
32+
33+
#### sinpi( x )
34+
35+
Computes `sin(πx)` more accurately than `sin(pi*x)`, especially for large `x`.
36+
37+
```javascript
38+
var y = sinpi( 0.0 );
39+
// returns 0.0
40+
41+
y = sinpi( 0.5 );
42+
// returns 1.0
43+
44+
y = sinpi( 0.9 );
45+
// returns ~0.309
46+
47+
y = sinpi( NaN );
48+
// returns NaN
49+
```
50+
51+
</section>
52+
53+
<!-- /.usage -->
54+
55+
<section class="examples">
56+
57+
## Examples
58+
59+
<!-- eslint no-undef: "error" -->
60+
61+
```javascript
62+
var uniform = require( '@stdlib/random/array/uniform' );
63+
var logEachMap = require( '@stdlib/console/log-each-map' );
64+
var sinpi = require( '@stdlib/math/base/special/sinpi' );
65+
66+
var opts = {
67+
'dtype': 'float64'
68+
};
69+
var x = uniform( 100, -100.0, 100.0, opts );
70+
71+
logEachMap( 'sin( π * %0.4f ) = %0.4f', x, sinpi );
72+
```
73+
74+
</section>
75+
76+
<!-- /.examples -->
77+
78+
<!-- C interface documentation. -->
79+
80+
* * *
81+
82+
<section class="c">
83+
84+
## C APIs
85+
86+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
87+
88+
<section class="intro">
89+
90+
</section>
91+
92+
<!-- /.intro -->
93+
94+
<!-- C usage documentation. -->
95+
96+
<section class="usage">
97+
98+
### Usage
99+
100+
```c
101+
#include "stdlib/math/base/special/sinpi.h"
102+
```
103+
104+
#### stdlib_base_sinpi( x )
105+
106+
Computes `sin(πx)` more accurately than `sin(pi*x)`, especially for large `x`.
107+
108+
```c
109+
double y = stdlib_base_sinpi( 0.5 );
110+
// returns 1.0
111+
```
112+
113+
The function accepts the following arguments:
114+
115+
- **x**: `[in] double` input value.
116+
117+
```c
118+
double stdlib_base_sinpi( const double x );
119+
```
120+
121+
</section>
122+
123+
<!-- /.usage -->
124+
125+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
126+
127+
<section class="notes">
128+
129+
</section>
130+
131+
<!-- /.notes -->
132+
133+
<!-- C API usage examples. -->
134+
135+
<section class="examples">
136+
137+
### Examples
138+
139+
```c
140+
#include "stdlib/math/base/special/sinpi.h"
141+
#include <stdio.h>
142+
143+
int main( void ) {
144+
const double x[] = { 0.0, 0.523, 0.785, 1.047, 3.14 };
145+
146+
double y;
147+
int i;
148+
for ( i = 0; i < 5; i++ ) {
149+
y = stdlib_base_sinpi( x[ i ] );
150+
printf( "sinpi(%lf) = %lf\n", x[ i ], y );
151+
}
152+
}
153+
```
154+
155+
</section>
156+
157+
<!-- /.examples -->
158+
159+
</section>
160+
161+
<!-- /.c -->
162+
163+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
164+
165+
<section class="related">
166+
167+
* * *
168+
169+
## See Also
170+
171+
- <span class="package-name">[`@stdlib/math/base/special/sin`][@stdlib/math/base/special/sin]</span><span class="delimiter">: </span><span class="description">compute the sine of a number.</span>
172+
173+
</section>
174+
175+
<!-- /.related -->
176+
177+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
178+
179+
<section class="links">
180+
181+
[@stdlib/constants/float64/pi]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/constants/float64/pi
182+
183+
<!-- <related-links> -->
184+
185+
[@stdlib/math/base/special/sin]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/sin
186+
187+
<!-- </related-links> -->
188+
189+
</section>
190+
191+
<!-- /.links -->
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 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 bench = require( '@stdlib/bench' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var pkg = require( './../package.json' ).name;
27+
var sinpi = require( './../lib' );
28+
29+
30+
// MAIN //
31+
32+
bench( pkg, function benchmark( b ) {
33+
var x;
34+
var y;
35+
var i;
36+
37+
x = uniform( 100, -5.0e6, 5.0e6 );
38+
39+
b.tic();
40+
for ( i = 0; i < b.iterations; i++ ) {
41+
y = sinpi( x[ i%x.length ] );
42+
if ( isnan( y ) ) {
43+
b.fail( 'should not return NaN' );
44+
}
45+
}
46+
b.toc();
47+
if ( isnan( y ) ) {
48+
b.fail( 'should not return NaN' );
49+
}
50+
b.pass( 'benchmark finished' );
51+
b.end();
52+
});
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 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 resolve = require( 'path' ).resolve;
24+
var bench = require( '@stdlib/bench' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
26+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
27+
var tryRequire = require( '@stdlib/utils/try-require' );
28+
var pkg = require( './../package.json' ).name;
29+
30+
31+
// VARIABLES //
32+
33+
var sinpi = tryRequire( resolve( __dirname, './../lib/native.js' ) );
34+
var opts = {
35+
'skip': ( sinpi instanceof Error )
36+
};
37+
38+
39+
// MAIN //
40+
41+
bench( pkg+'::native', opts, function benchmark( b ) {
42+
var x;
43+
var y;
44+
var i;
45+
46+
x = uniform( 100, -5.0e6, 5.0e6 );
47+
48+
b.tic();
49+
for ( i = 0; i < b.iterations; i++ ) {
50+
y = sinpi( x[ i%x.length ] );
51+
if ( isnan( y ) ) {
52+
b.fail( 'should not return NaN' );
53+
}
54+
}
55+
b.toc();
56+
if ( isnan( y ) ) {
57+
b.fail( 'should not return NaN' );
58+
}
59+
b.pass( 'benchmark finished' );
60+
b.end();
61+
});

0 commit comments

Comments
 (0)