Skip to content

Commit e360ede

Browse files
committed
feat: add math/base/special/sinpif
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: passed - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent a653e26 commit e360ede

File tree

32 files changed

+570
-825
lines changed

32 files changed

+570
-825
lines changed

lib/node_modules/@stdlib/math/base/special/sinpif/README.md

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
@license Apache-2.0
44
5-
Copyright (c) 2018 The Stdlib Authors.
5+
Copyright (c) 2025 The Stdlib Authors.
66
77
Licensed under the Apache License, Version 2.0 (the "License");
88
you may not use this file except in compliance with the License.
@@ -18,33 +18,33 @@ limitations under the License.
1818
1919
-->
2020

21-
# sinpi
21+
# sinpif
2222

23-
> Compute the [sine][@stdlib/math/base/special/sin] of a number times [π][@stdlib/constants/float64/pi].
23+
> Compute the [sine][@stdlib/math/base/special/sinf] of a number times [π][@stdlib/constants/float32/pi].
2424
2525
<section class="usage">
2626

2727
## Usage
2828

2929
```javascript
30-
var sinpi = require( '@stdlib/math/base/special/sinpi' );
30+
var sinpif = require( '@stdlib/math/base/special/sinpif' );
3131
```
3232

33-
#### sinpi( x )
33+
#### sinpif( x )
3434

35-
Computes `sin(πx)` more accurately than `sin(pi*x)`, especially for large `x`.
35+
Computes `sin(πx)` in single-precision floating-point format more accurately than `sin(pi*x)`, especially for large `x`.
3636

3737
```javascript
38-
var y = sinpi( 0.0 );
38+
var y = sinpif( 0.0 );
3939
// returns 0.0
4040

41-
y = sinpi( 0.5 );
41+
y = sinpif( 0.5 );
4242
// returns 1.0
4343

44-
y = sinpi( 0.9 );
44+
y = sinpif( 0.9 );
4545
// returns ~0.309
4646

47-
y = sinpi( NaN );
47+
y = sinpif( NaN );
4848
// returns NaN
4949
```
5050

@@ -61,14 +61,14 @@ y = sinpi( NaN );
6161
```javascript
6262
var uniform = require( '@stdlib/random/array/uniform' );
6363
var logEachMap = require( '@stdlib/console/log-each-map' );
64-
var sinpi = require( '@stdlib/math/base/special/sinpi' );
64+
var sinpif = require( '@stdlib/math/base/special/sinpif' );
6565

6666
var opts = {
67-
'dtype': 'float64'
67+
'dtype': 'float32'
6868
};
6969
var x = uniform( 100, -100.0, 100.0, opts );
7070

71-
logEachMap( 'sin( π * %0.4f ) = %0.4f', x, sinpi );
71+
logEachMap( 'sin( π * %0.4f ) = %0.4f', x, sinpif );
7272
```
7373

7474
</section>
@@ -98,24 +98,24 @@ logEachMap( 'sin( π * %0.4f ) = %0.4f', x, sinpi );
9898
### Usage
9999

100100
```c
101-
#include "stdlib/math/base/special/sinpi.h"
101+
#include "stdlib/math/base/special/sinpif.h"
102102
```
103103

104-
#### stdlib_base_sinpi( x )
104+
#### stdlib_base_sinpif( x )
105105

106-
Computes `sin(πx)` more accurately than `sin(pi*x)`, especially for large `x`.
106+
Computes `sin(πx)` in single-precision floating-point format more accurately than `sin(pi*x)`, especially for large `x`.
107107

108108
```c
109-
double y = stdlib_base_sinpi( 0.5 );
110-
// returns 1.0
109+
float y = stdlib_base_sinpif( 0.5f );
110+
// returns 1.0f
111111
```
112112

113113
The function accepts the following arguments:
114114

115-
- **x**: `[in] double` input value.
115+
- **x**: `[in] float` input value.
116116

117117
```c
118-
double stdlib_base_sinpi( const double x );
118+
float stdlib_base_sinpif( const float x );
119119
```
120120
121121
</section>
@@ -137,17 +137,17 @@ double stdlib_base_sinpi( const double x );
137137
### Examples
138138
139139
```c
140-
#include "stdlib/math/base/special/sinpi.h"
140+
#include "stdlib/math/base/special/sinpif.h"
141141
#include <stdio.h>
142142
143143
int main( void ) {
144-
const double x[] = { 0.0, 0.523, 0.785, 1.047, 3.14 };
144+
const float x[] = { 0.0f, 0.523f, 0.785f, 1.047f, 3.14f };
145145
146-
double y;
146+
float y;
147147
int i;
148148
for ( i = 0; i < 5; i++ ) {
149-
y = stdlib_base_sinpi( x[ i ] );
150-
printf( "sinpi(%lf) = %lf\n", x[ i ], y );
149+
y = stdlib_base_sinpif( x[ i ] );
150+
printf( "sin( π * %f ) = %f\n", x[ i ], y );
151151
}
152152
}
153153
```
@@ -164,12 +164,6 @@ int main( void ) {
164164

165165
<section class="related">
166166

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-
173167
</section>
174168

175169
<!-- /.related -->
@@ -178,11 +172,11 @@ int main( void ) {
178172

179173
<section class="links">
180174

181-
[@stdlib/constants/float64/pi]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/constants/float64/pi
175+
[@stdlib/math/base/special/sinf]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/sinf
182176

183-
<!-- <related-links> -->
177+
[@stdlib/constants/float32/pi]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/constants/float32/pi
184178

185-
[@stdlib/math/base/special/sin]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/sin
179+
<!-- <related-links> -->
186180

187181
<!-- </related-links> -->
188182

lib/node_modules/@stdlib/math/base/special/sinpif/benchmark/benchmark.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2018 The Stdlib Authors.
4+
* Copyright (c) 2025 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -22,9 +22,9 @@
2222

2323
var bench = require( '@stdlib/bench' );
2424
var uniform = require( '@stdlib/random/array/uniform' );
25-
var isnan = require( '@stdlib/math/base/assert/is-nan' );
25+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2626
var pkg = require( './../package.json' ).name;
27-
var sinpi = require( './../lib' );
27+
var sinpif = require( './../lib' );
2828

2929

3030
// MAIN //
@@ -34,17 +34,19 @@ bench( pkg, function benchmark( b ) {
3434
var y;
3535
var i;
3636

37-
x = uniform( 100, -5.0e6, 5.0e6 );
37+
x = uniform( 100, -5.0e6, 5.0e6, {
38+
'dtype': 'float32'
39+
});
3840

3941
b.tic();
4042
for ( i = 0; i < b.iterations; i++ ) {
41-
y = sinpi( x[ i%x.length ] );
42-
if ( isnan( y ) ) {
43+
y = sinpif( x[ i%x.length ] );
44+
if ( isnanf( y ) ) {
4345
b.fail( 'should not return NaN' );
4446
}
4547
}
4648
b.toc();
47-
if ( isnan( y ) ) {
49+
if ( isnanf( y ) ) {
4850
b.fail( 'should not return NaN' );
4951
}
5052
b.pass( 'benchmark finished' );

lib/node_modules/@stdlib/math/base/special/sinpif/benchmark/benchmark.native.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2024 The Stdlib Authors.
4+
* Copyright (c) 2025 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -23,16 +23,16 @@
2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
2525
var uniform = require( '@stdlib/random/array/uniform' );
26-
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2727
var tryRequire = require( '@stdlib/utils/try-require' );
2828
var pkg = require( './../package.json' ).name;
2929

3030

3131
// VARIABLES //
3232

33-
var sinpi = tryRequire( resolve( __dirname, './../lib/native.js' ) );
33+
var sinpif = tryRequire( resolve( __dirname, './../lib/native.js' ) );
3434
var opts = {
35-
'skip': ( sinpi instanceof Error )
35+
'skip': ( sinpif instanceof Error )
3636
};
3737

3838

@@ -43,17 +43,19 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4343
var y;
4444
var i;
4545

46-
x = uniform( 100, -5.0e6, 5.0e6 );
46+
x = uniform( 100, -5.0e6, 5.0e6, {
47+
'dtype': 'float32'
48+
});
4749

4850
b.tic();
4951
for ( i = 0; i < b.iterations; i++ ) {
50-
y = sinpi( x[ i%x.length ] );
51-
if ( isnan( y ) ) {
52+
y = sinpif( x[ i%x.length ] );
53+
if ( isnanf( y ) ) {
5254
b.fail( 'should not return NaN' );
5355
}
5456
}
5557
b.toc();
56-
if ( isnan( y ) ) {
58+
if ( isnanf( y ) ) {
5759
b.fail( 'should not return NaN' );
5860
}
5961
b.pass( 'benchmark finished' );

lib/node_modules/@stdlib/math/base/special/sinpif/benchmark/c/native/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#/
22
# @license Apache-2.0
33
#
4-
# Copyright (c) 2024 The Stdlib Authors.
4+
# Copyright (c) 2025 The Stdlib Authors.
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.

lib/node_modules/@stdlib/math/base/special/sinpif/benchmark/c/native/benchmark.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2024 The Stdlib Authors.
4+
* Copyright (c) 2025 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -16,14 +16,14 @@
1616
* limitations under the License.
1717
*/
1818

19-
#include "stdlib/math/base/special/sinpi.h"
19+
#include "stdlib/math/base/special/sinpif.h"
2020
#include <stdlib.h>
2121
#include <stdio.h>
2222
#include <math.h>
2323
#include <time.h>
2424
#include <sys/time.h>
2525

26-
#define NAME "sinpi"
26+
#define NAME "sinpif"
2727
#define ITERATIONS 1000000
2828
#define REPEATS 3
2929

@@ -75,13 +75,15 @@ static double tic( void ) {
7575
}
7676

7777
/**
78-
* Generates a random number on the interval [0,1).
78+
* Generates a random number on the interval [min,max).
7979
*
80-
* @return random number
80+
* @param min minimum value (inclusive)
81+
* @param max maximum value (exclusive)
82+
* @return random number
8183
*/
82-
static double rand_double( void ) {
83-
int r = rand();
84-
return (double)r / ( (double)RAND_MAX + 1.0 );
84+
static float random_uniform( const float min, const float max ) {
85+
float v = (float)rand() / ( (float)RAND_MAX + 1.0f );
86+
return min + ( v*(max-min) );
8587
}
8688

8789
/**
@@ -90,19 +92,19 @@ static double rand_double( void ) {
9092
* @return elapsed time in seconds
9193
*/
9294
static double benchmark( void ) {
93-
double x[ 100 ];
95+
float x[ 100 ];
9496
double elapsed;
95-
double y;
9697
double t;
98+
float y;
9799
int i;
98100

99101
for ( i = 0; i < 100; i++ ) {
100-
x[ i ] = ( 1.0e7 * rand_double() ) - 5.0e6;
102+
x[ i ] = random_uniform( -5.0e6, 5.0e6 );
101103
}
102104

103105
t = tic();
104106
for ( i = 0; i < ITERATIONS; i++ ) {
105-
y = stdlib_base_sinpi( x[ i%100 ] );
107+
y = stdlib_base_sinpif( x[ i%100 ] );
106108
if ( y != y ) {
107109
printf( "should not return NaN\n" );
108110
break;

0 commit comments

Comments
 (0)