Skip to content

Commit f033ec6

Browse files
committed
feat: add math/base/special/kernel-cosf
--- 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 7258b6e commit f033ec6

File tree

27 files changed

+263
-174
lines changed

27 files changed

+263
-174
lines changed

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
@license Apache-2.0
44
5-
Copyright (c) 2022 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.
@@ -60,15 +60,13 @@ v = kernelCosf( NaN );
6060

6161
```javascript
6262
var linspace = require( '@stdlib/array/base/linspace' );
63+
var logEachMap = require( '@stdlib/console/log-each-map' );
6364
var PI = require( '@stdlib/constants/float64/pi' );
6465
var kernelCosf = require( '@stdlib/math/base/special/kernel-cosf' );
6566

6667
var x = linspace( -PI/4.0, PI/4.0, 100 );
6768

68-
var i;
69-
for ( i = 0; i < x.length; i++ ) {
70-
console.log( 'kernelCosf(%d) = %d', x[ i ], kernelCosf( x[ i ] ) );
71-
}
69+
logEachMap( 'kernelCosf(%0.4f) = %0.4f', x, kernelCosf );
7270
```
7371

7472
</section>
@@ -106,19 +104,19 @@ for ( i = 0; i < x.length; i++ ) {
106104
Computes the [cosine][cosine] of a single-precision floating-point number on `[-π/4, π/4]`.
107105

108106
```c
109-
float v = stdlib_base_kernel_cosf( 0.0f );
107+
float v = stdlib_base_kernel_cosf( 0.0 );
110108
// returns ~0.0f
111109

112-
v = stdlib_base_kernel_cosf( 3.141592653589793/6.0f );
110+
v = stdlib_base_kernel_cosf( 3.141592653589793/6.0 );
113111
// returns ~0.866f
114112
```
115113

116114
The function accepts the following arguments:
117115

118-
- **x**: `[in] float` input value (in radians, assumed to be bounded by `~pi/4` in magnitude).
116+
- **x**: `[in] double` input value (in radians, assumed to be bounded by `~pi/4` in magnitude).
119117

120118
```c
121-
float stdlib_base_kernel_cosf( const float x );
119+
float stdlib_base_kernel_cosf( const double x );
122120
```
123121
124122
</section>
@@ -144,13 +142,13 @@ float stdlib_base_kernel_cosf( const float x );
144142
#include <stdio.h>
145143
146144
int main( void ) {
147-
const float x[] = { -0.7853981633974483f, -0.6108652381980153f, -0.4363323129985824f, -0.26179938779914946f, -0.08726646259971649f, 0.08726646259971649f, 0.26179938779914935f, 0.43633231299858233f, 0.6108652381980153f, 0.7853981633974483f };
145+
const double x[] = { -0.7853981633974483, -0.6108652381980153, -0.4363323129985824, -0.26179938779914946, -0.08726646259971649, 0.08726646259971649, 0.26179938779914935, 0.43633231299858233, 0.6108652381980153, 0.7853981633974483 };
148146
149-
float v;
147+
float out;
150148
int i;
151149
for ( i = 0; i < 10; i++ ) {
152-
v = stdlib_base_kernel_cosf( x[ i ] );
153-
printf( "kernelCosf(%f) = %f\n", x[ i ], v );
150+
out = stdlib_base_kernel_cosf( x[ i ] );
151+
printf ( "x[ i ]: %lf, out: %f\n", x[ i ], out );
154152
}
155153
}
156154
```

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

Lines changed: 6 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) 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,7 +22,7 @@
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 PI = require( '@stdlib/constants/float64/pi' );
2727
var pkg = require( './../package.json' ).name;
2828
var kernelCosf = require( './../lib' );
@@ -35,19 +35,17 @@ bench( pkg, function benchmark( b ) {
3535
var y;
3636
var i;
3737

38-
x = uniform( 100, -PI/4.0, PI/4.0, {
39-
'dtype': 'float32'
40-
});
38+
x = uniform( 100, -PI/4.0, PI/4.0 );
4139

4240
b.tic();
4341
for ( i = 0; i < b.iterations; i++ ) {
44-
y = kernelCosf( x[ i % x.length ] );
45-
if ( isnan( y ) ) {
42+
y = kernelCosf( x[ i%x.length ] );
43+
if ( isnanf( y ) ) {
4644
b.fail( 'should not return NaN' );
4745
}
4846
}
4947
b.toc();
50-
if ( isnan( y ) ) {
48+
if ( isnanf( y ) ) {
5149
b.fail( 'should not return NaN' );
5250
}
5351
b.pass( 'benchmark finished' );

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

Lines changed: 6 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) 2022 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,7 +23,7 @@
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 PI = require( '@stdlib/constants/float64/pi' );
2828
var tryRequire = require( '@stdlib/utils/try-require' );
2929
var pkg = require( './../package.json' ).name;
@@ -44,19 +44,17 @@ 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-
'dtype': 'float32'
49-
});
47+
x = uniform( 100, -PI/4.0, PI/4.0 );
5048

5149
b.tic();
5250
for ( i = 0; i < b.iterations; i++ ) {
53-
y = kernelCosf( x[ i % x.length ] );
54-
if ( isnan( y ) ) {
51+
y = kernelCosf( x[ i%x.length ] );
52+
if ( isnanf( y ) ) {
5553
b.fail( 'should not return NaN' );
5654
}
5755
}
5856
b.toc();
59-
if ( isnan( y ) ) {
57+
if ( isnanf( y ) ) {
6058
b.fail( 'should not return NaN' );
6159
}
6260
b.pass( 'benchmark finished' );

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

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#/
22
# @license Apache-2.0
33
#
4-
# Copyright (c) 2022 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.
@@ -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)
@@ -144,4 +144,3 @@ clean:
144144
$(QUIET) -rm -f *.o *.out
145145

146146
.PHONY: clean
147-

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2022 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.
@@ -79,9 +79,9 @@ static double tic( void ) {
7979
*
8080
* @return random number
8181
*/
82-
static float rand_float( void ) {
82+
static double rand_double( void ) {
8383
int r = rand();
84-
return (float)r / ( (float)RAND_MAX + 1.0f );
84+
return (double)r / ( (double)RAND_MAX + 1.0 );
8585
}
8686

8787
/**
@@ -90,14 +90,14 @@ static float rand_float( void ) {
9090
* @return elapsed time in seconds
9191
*/
9292
static double benchmark( void ) {
93-
float x[ 100 ];
9493
double elapsed;
95-
double z;
94+
double x[ 100 ];
9695
double t;
96+
float z;
9797
int i;
9898

9999
for ( i = 0; i < 100; i++ ) {
100-
x[ i ] = ( ( rand_float()*2.0f ) - 1.0f ) * 0.7853981633974483f;
100+
x[ i ] = ( ( rand_double()*2.0 ) - 1.0 ) * 0.7853981633974483;
101101
}
102102

103103
t = tic();

lib/node_modules/@stdlib/math/base/special/kernel-cosf/binding.gyp

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

lib/node_modules/@stdlib/math/base/special/kernel-cosf/docs/repl.txt

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,27 @@
11

2-
{{alias}}( x, y )
3-
Computes the cosine of a double-precision floating-point number on the
2+
{{alias}}( x )
3+
Computes the cosine of a single-precision floating-point number on the
44
interval [-π/4, π/4].
55

6-
For increased accuracy, the number for which the cosine should be evaluated
7-
can be supplied as a double-double number (i.e., a non-evaluated sum of two
8-
double-precision floating-point numbers `x` and `y`).
9-
10-
The two numbers must satisfy `|y| < 0.5 * ulp( x )`.
11-
12-
If either argument is `NaN`, the function returns `NaN`.
6+
If provided `NaN`, the function returns `NaN`.
137

148
Parameters
159
----------
1610
x: number
1711
Input value (in radians).
1812

19-
y: number
20-
Tail of `x`.
21-
2213
Returns
2314
-------
2415
out: number
2516
Cosine.
2617

2718
Examples
2819
--------
29-
> var out = {{alias}}( 0.0, 0.0 )
20+
> var out = {{alias}}( 0.0 )
3021
~1.0
31-
> out = {{alias}}( {{alias:@stdlib/constants/float64/pi}}/6.0, 0.0 )
22+
> out = {{alias}}( {{alias:@stdlib/constants/float64/pi}}/6.0 )
3223
~0.866
33-
> out = {{alias}}( 0.785, -1.144e-17 )
24+
> out = {{alias}}( 0.785 )
3425
~0.707
3526
> out = {{alias}}( NaN )
3627
NaN
Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2019 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.
@@ -19,36 +19,34 @@
1919
// TypeScript Version: 4.1
2020

2121
/**
22-
* Computes the cosine of a double-precision floating-point number on `[-π/4, π/4]`.
22+
* Computes the cosine of a single-precision floating-point number on \\( \[-\pi/4, \pi/4] \\), where \\( \pi/4 \approx 0.785398164 \\).
2323
*
2424
* ## Notes
2525
*
26-
* - For increased accuracy, the number for which the cosine should be evaluated can be supplied as a double-double number (i.e., a non-evaluated sum of two double-precision floating-point numbers `x` and `y`).
27-
* - The two numbers must satisfy `|y| < 0.5 * ulp( x )`.
26+
* - \\( | \cos(x) - c(x) | < 2^{-34.1} \\), where \\( 2^{-34.1} \approx \[ -5.37 \times 10^{-11}, 5.295 \times 10^{-11} \] \\).
2827
*
2928
* @param x - input value (in radians, assumed to be bounded by ~pi/4 in magnitude)
30-
* @param y - tail of `x`
3129
* @returns cosine
3230
*
3331
* @example
34-
* var v = kernelCos( 0.0, 0.0 );
32+
* var v = kernelCosf( 0.0 );
3533
* // returns ~1.0
3634
*
3735
* @example
38-
* var v = kernelCos( 3.141592653589793/6.0, 0.0 );
36+
* var v = kernelCosf( 3.141592653589793/6.0 );
3937
* // returns ~0.866
4038
*
4139
* @example
42-
* var v = kernelCos( 0.785, -1.144e-17 );
40+
* var v = kernelCosf( 0.785 );
4341
* // returns ~0.707
4442
*
4543
* @example
46-
* var v = kernelCos( NaN, 0.0 );
44+
* var v = kernelCosf( NaN );
4745
* // returns NaN
4846
*/
49-
declare function kernelCos( x: number, y: number ): number;
47+
declare function kernelCosf( x: number ): number;
5048

5149

5250
// EXPORTS //
5351

54-
export = kernelCos;
52+
export = kernelCosf;

0 commit comments

Comments
 (0)