Skip to content

Commit 85195f5

Browse files
committed
feat: add math/base/special/kernel-sinf
--- 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: na - 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 bd89c02 commit 85195f5

File tree

27 files changed

+459
-582
lines changed

27 files changed

+459
-582
lines changed

lib/node_modules/@stdlib/math/base/special/kernel-sinf/README.md

Lines changed: 18 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
88
you may not use this file except in compliance with the License.
99
You may obtain a copy of the License at
1010
11-
http://www.apache.org/licenses/LICENSE-2.0
11+
http://www.apache.org/licenses/LICENSE-2.0
1212
1313
Unless required by applicable law or agreed to in writing, software
1414
distributed under the License is distributed on an "AS IS" BASIS,
@@ -35,52 +35,23 @@ var kernelSinf = require( '@stdlib/math/base/special/kernel-sinf' );
3535
Computes the [sine][sine] of a single-precision floating-point number on `[-π/4, π/4]`.
3636

3737
```javascript
38-
var v = kernelSinf( 0.0, 0.0 );
38+
var v = kernelSinf( 0.0 );
3939
// returns ~0.0
4040

41-
v = kernelSinf( 3.14159/6.0, 0.0 );
41+
v = kernelSinf( 3.141592653589793/6.0 );
4242
// returns ~0.5
4343

44-
v = kernelSinf( 0.619, 9.279e-10 );
45-
// returns ~0.58
44+
v = kernelSinf( 0.619 );
45+
// returns ~0.580
4646

47-
v = kernelSinf( NaN, 0.0 );
48-
// returns NaN
49-
50-
v = kernelSinf( 3.0, NaN );
51-
// returns NaN
52-
53-
v = kernelSinf( NaN, NaN );
47+
v = kernelSinf( NaN );
5448
// returns NaN
5549
```
5650

5751
</section>
5852

5953
<!-- /.usage -->
6054

61-
<section class="notes">
62-
63-
## Notes
64-
65-
- For increased accuracy, the number for which the [sine][sine] should be evaluated can be supplied as a [single-double number][single-arithmetic] (i.e., a non-evaluated sum of two [single-precision floating-point numbers][ieee754] `x` and `y`).
66-
67-
- As components of a [single-double number][single-arithmetic], the two [single-precision floating-point numbers][ieee754] `x` and `y` must satisfy
68-
69-
<!-- <equation class="equation" label="eq:single_double_inequality" align="center" raw="|y| \leq \frac{1}{2} \operatorname{ulp}(x)" alt="Inequality for the two components of a single-double number."> -->
70-
71-
<div class="equation" align="center" data-raw-text="|y| \leq \frac{1}{2} \operatorname{ulp}(x)" data-equation="eq:single_double_inequality">
72-
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@819807799dc2df7eb037d5901624fa3169bce774/lib/node_modules/@stdlib/math/base/special/kernel-sin/docs/img/equation_double_double_inequality.svg" alt="Inequality for the two components of a single-double number.">
73-
<br>
74-
</div>
75-
76-
<!-- </equation> -->
77-
78-
where `ulp` stands for [units in the last place][ulp].
79-
80-
</section>
81-
82-
<!-- /.notes -->
83-
8455
<section class="examples">
8556

8657
## Examples
@@ -89,15 +60,13 @@ v = kernelSinf( NaN, NaN );
8960

9061
```javascript
9162
var linspace = require( '@stdlib/array/base/linspace' );
92-
var PI = require( '@stdlib/constants/float32/pi' );
63+
var logEachMap = require( '@stdlib/console/log-each-map' );
64+
var PI = require( '@stdlib/constants/float64/pi' );
9365
var kernelSinf = require( '@stdlib/math/base/special/kernel-sinf' );
9466

9567
var x = linspace( -PI/4.0, PI/4.0, 100 );
9668

97-
var i;
98-
for ( i = 0; i < x.length; i++ ) {
99-
console.log( 'sine(%d) = %d', x[ i ], kernelSinf( x[ i ], 0.0 ) );
100-
}
69+
logEachMap( 'kernelSinf(%0.4f) = %0.4f', x, kernelSinf );
10170
```
10271

10372
</section>
@@ -130,25 +99,24 @@ for ( i = 0; i < x.length; i++ ) {
13099
#include "stdlib/math/base/special/kernel_sinf.h"
131100
```
132101

133-
#### stdlib_base_kernel_sinf( x, y )
102+
#### stdlib_base_kernel_sinf( x )
134103

135104
Computes the [sine][sine] of a single-precision floating-point number on `[-π/4, π/4]`.
136105

137106
```c
138-
float out = stdlib_base_kernel_sinf( 0.0f, 0.0f );
107+
float v = stdlib_base_kernel_sinf( 0.0 );
139108
// returns ~0.0f
140109

141-
out = stdlib_base_kernel_sinf( 0.619f, 9.279e-10f );
142-
// returns ~0.58f
110+
v = stdlib_base_kernel_sinf( 3.141592653589793/6.0 );
111+
// returns ~0.5f
143112
```
144113

145114
The function accepts the following arguments:
146115

147-
- **x**: `[in] float` input value (in radians, assumed to be bounded by `~pi/4` in magnitude).
148-
- **y**: `[in] float` tail of `x`.
116+
- **x**: `[in] double` input value (in radians, assumed to be bounded by `~pi/4` in magnitude).
149117

150118
```c
151-
float stdlib_base_kernel_sinf( const float x, const float y );
119+
float stdlib_base_kernel_sinf( const double x );
152120
```
153121
154122
</section>
@@ -159,10 +127,6 @@ float stdlib_base_kernel_sinf( const float x, const float y );
159127
160128
<section class="notes">
161129
162-
### Notes
163-
164-
- For increased accuracy, the number for which the [sine][sine] should be evaluated can be supplied as a [single-double number][single-arithmetic] (i.e., a non-evaluated sum of two [single-precision floating-point numbers][ieee754] `x` and `y`).
165-
166130
</section>
167131
168132
<!-- /.notes -->
@@ -178,13 +142,13 @@ float stdlib_base_kernel_sinf( const float x, const float y );
178142
#include <stdio.h>
179143
180144
int main( void ) {
181-
const float x[] = { -0.7853982f, -0.6108652f, -0.4363323f, -0.2617994f, -0.08726646f, 0.08726646f, 0.2617994f, 0.4363323f, 0.6108652f, 0.7853982f };
145+
const double x[] = { -0.7853981633974483, -0.6108652381980153, -0.4363323129985824, -0.26179938779914946, -0.08726646259971649, 0.08726646259971649, 0.26179938779914935, 0.43633231299858233, 0.6108652381980153, 0.7853981633974483 };
182146
183147
float out;
184148
int i;
185149
for ( i = 0; i < 10; i++ ) {
186-
out = stdlib_base_kernel_sinf( x[ i ], 0.0f );
187-
printf ( "x: %f, y: %f, out: %f\n", x[ i ], 0.0f, out );
150+
out = stdlib_base_kernel_sinf( x[ i ] );
151+
printf ( "x[ i ]: %lf, out: %f\n", x[ i ], out );
188152
}
189153
}
190154
```
@@ -201,15 +165,6 @@ int main( void ) {
201165

202166
<section class="related">
203167

204-
* * *
205-
206-
## See Also
207-
208-
- <span class="package-name">[`@stdlib/math/base/special/kernel-cosf`][@stdlib/math/base/special/kernel-cosf]</span><span class="delimiter">: </span><span class="description">compute the cosine of a single-precision floating-point number on \[-π/4, π/4].</span>
209-
- <span class="package-name">[`@stdlib/math/base/special/kernel-tanf`][@stdlib/math/base/special/kernel-tanf]</span><span class="delimiter">: </span><span class="description">compute the tangent of a single-precision floating-point number on \[-π/4, π/4].</span>
210-
- <span class="package-name">[`@stdlib/math/base/special/sinf`][@stdlib/math/base/special/sinf]</span><span class="delimiter">: </span><span class="description">compute the sine of a number.</span>
211-
- <span class="package-name">[`@stdlib/math/base/special/kernel-sin`][@stdlib/math/base/special/kernel-sin]</span><span class="delimiter">: </span><span class="description">compute the sine of a double-precision floating-point number on \[-π/4, π/4].</span>
212-
213168
</section>
214169

215170
<!-- /.related -->
@@ -220,20 +175,8 @@ int main( void ) {
220175

221176
[sine]: https://en.wikipedia.org/wiki/Sine
222177

223-
[single-arithmetic]: https://en.wikipedia.org/wiki/Single-precision_floating-point_format
224-
225-
[ieee754]: https://en.wikipedia.org/wiki/IEEE_floating_point
226-
227-
[ulp]: https://en.wikipedia.org/wiki/Unit_in_the_last_place
228-
229178
<!-- <related-links> -->
230179

231-
[@stdlib/math/base/special/kernel-cos]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/kernel-cos
232-
233-
[@stdlib/math/base/special/kernel-tan]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/kernel-tan
234-
235-
[@stdlib/math/base/special/sin]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/sin
236-
237180
<!-- </related-links> -->
238181

239182
</section>

lib/node_modules/@stdlib/math/base/special/kernel-sinf/benchmark/benchmark.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
2525
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
26-
var PI = require( '@stdlib/constants/float32/pi' );
26+
var PI = require( '@stdlib/constants/float64/pi' );
2727
var pkg = require( './../package.json' ).name;
2828
var kernelSinf = require( './../lib' );
2929

@@ -35,10 +35,11 @@ bench( pkg, function benchmark( b ) {
3535
var y;
3636
var i;
3737

38+
x = uniform( 100, -PI/4.0, PI/4.0 );
39+
3840
b.tic();
3941
for ( i = 0; i < b.iterations; i++ ) {
40-
x = ( randu() * PI/2.0 ) - ( PI/4.0 );
41-
y = kernelSinf( x, 0.0 );
42+
y = kernelSinf( x[ i%x.length ] );
4243
if ( isnanf( y ) ) {
4344
b.fail( 'should not return NaN' );
4445
}

lib/node_modules/@stdlib/math/base/special/kernel-sinf/benchmark/benchmark.native.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var randu = require( '@stdlib/random/base/randu' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
2626
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
27-
var PI = require( '@stdlib/constants/float32/pi' );
27+
var PI = require( '@stdlib/constants/float64/pi' );
2828
var tryRequire = require( '@stdlib/utils/try-require' );
2929
var pkg = require( './../package.json' ).name;
3030

3131

3232
// VARIABLES //
3333

34-
var kernelSin = tryRequire( resolve( __dirname, './../lib/native.js' ) );
34+
var kernelSinf = tryRequire( resolve( __dirname, './../lib/native.js' ) );
3535
var opts = {
36-
'skip': ( kernelSin instanceof Error )
36+
'skip': ( kernelSinf instanceof Error )
3737
};
3838

3939

@@ -44,10 +44,11 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4444
var y;
4545
var i;
4646

47+
x = uniform( 100, -PI/4.0, PI/4.0 );
48+
4749
b.tic();
4850
for ( i = 0; i < b.iterations; i++ ) {
49-
x = ( randu() * PI/2.0 ) - ( PI/4.0 );
50-
y = kernelSin( x, 0.0 );
51+
y = kernelSinf( x[ i%x.length ] );
5152
if ( isnanf( y ) ) {
5253
b.fail( 'should not return NaN' );
5354
}

lib/node_modules/@stdlib/math/base/special/kernel-sinf/benchmark/c/native/Makefile

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ c_targets := benchmark.out
8888
# RULES #
8989

9090
#/
91-
# Compiles source files.
91+
# Compiles C source files.
9292
#
93-
# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`)
94-
# @param {string} [CFLAGS] - C compiler options
95-
# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`)
96-
# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`)
97-
# @param {string} [SOURCE_FILES] - list of source files
93+
# @param {string} SOURCE_FILES - list of C source files
94+
# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`)
95+
# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`)
9896
# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`)
99-
# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`)
97+
# @param {string} [C_COMPILER] - C compiler
98+
# @param {string} [CFLAGS] - C compiler flags
99+
# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code
100100
#
101101
# @example
102102
# make
@@ -112,13 +112,13 @@ all: $(c_targets)
112112
# Compiles C source files.
113113
#
114114
# @private
115-
# @param {string} CC - C compiler (e.g., `gcc`)
116-
# @param {string} CFLAGS - C compiler options
117-
# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`)
118-
# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`)
119-
# @param {string} SOURCE_FILES - list of source files
120-
# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`)
121-
# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`)
115+
# @param {string} SOURCE_FILES - list of C source files
116+
# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`)
117+
# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`)
118+
# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`)
119+
# @param {string} CC - C compiler
120+
# @param {string} CFLAGS - C compiler flags
121+
# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code
122122
#/
123123
$(c_targets): %.out: %.c
124124
$(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES)

lib/node_modules/@stdlib/math/base/special/kernel-sinf/benchmark/c/native/benchmark.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <time.h>
2424
#include <sys/time.h>
2525

26-
#define NAME "kernel_sin"
26+
#define NAME "kernel_sinf"
2727
#define ITERATIONS 1000000
2828
#define REPEATS 3
2929

@@ -91,15 +91,18 @@ static double rand_double( void ) {
9191
*/
9292
static double benchmark( void ) {
9393
double elapsed;
94-
double x;
95-
double z;
94+
double x[ 100 ];
9695
double t;
96+
float z;
9797
int i;
9898

99+
for ( i = 0; i < 100; i++ ) {
100+
x[ i ] = ( ( rand_double()*2.0 ) - 1.0 ) * 0.7853981633974483;
101+
}
102+
99103
t = tic();
100104
for ( i = 0; i < ITERATIONS; i++ ) {
101-
x = ( ( rand_double() * 2.0 ) - 1.0 ) * 0.7853981633974483;
102-
z = stdlib_base_kernel_sinf( x, 0.0 );
105+
z = stdlib_base_kernel_sinf( x[ i%100 ] );
103106
if ( z != z ) {
104107
printf( "should not return NaN\n" );
105108
break;

lib/node_modules/@stdlib/math/base/special/kernel-sinf/docs/img/equation_double_double_inequality.svg

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)