Skip to content

Commit b998d5b

Browse files
committed
feat: added implementation of math/base/special/sincosdf
Signed-off-by: Bhargav Dabhade <bhargava2005dabhade@gmail.com> --- 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: missing_dependencies - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - 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 896a1d4 commit b998d5b

35 files changed

Lines changed: 3102 additions & 0 deletions
Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2026 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+
# sincosdf
22+
23+
> Simultaneously compute the [sine][@stdlib/math/base/special/sindf] and [cosine][@stdlib/math/base/special/cosdf] of an angle measured in degrees (single-precision).
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var sincosdf = require( '@stdlib/math/base/special/sincosdf' );
31+
```
32+
33+
#### sincosdf( x )
34+
35+
Simultaneously computes the [sine][@stdlib/math/base/special/sindf] and [cosine][@stdlib/math/base/special/cosdf] of an angle measured in degrees (single-precision).
36+
37+
```javascript
38+
var v = sincosdf( 0.0 );
39+
// returns [ ~0.0, ~1.0 ]
40+
41+
v = sincosdf( 90.0 );
42+
// returns [ ~1.0, ~0.0 ]
43+
44+
v = sincosdf( -30.0 );
45+
// returns [ ~-0.5, ~0.8660254 ]
46+
```
47+
48+
#### sincosdf.assign( x, out, stride, offset )
49+
50+
Simultaneously computes the [sine][@stdlib/math/base/special/sindf] and [cosine][@stdlib/math/base/special/cosdf] of an angle measured in degrees and assigns the results to a provided output array.
51+
52+
```javascript
53+
var Float32Array = require( '@stdlib/array/float32' );
54+
55+
var out = new Float32Array( 2 );
56+
57+
var v = sincosdf.assign( 0.0, out, 1, 0 );
58+
// returns <Float32Array>[ ~0.0, ~1.0 ]
59+
60+
var bool = ( v === out );
61+
// returns true
62+
```
63+
64+
</section>
65+
66+
<!-- /.usage -->
67+
68+
<section class="examples">
69+
70+
## Examples
71+
72+
<!-- eslint no-undef: "error" -->
73+
74+
```javascript
75+
var uniform = require( '@stdlib/random/array/uniform' );
76+
var sincosdf = require( '@stdlib/math/base/special/sincosdf' );
77+
78+
var opts = {
79+
'dtype': 'float32'
80+
};
81+
var x = uniform( 100, -360.0, 360.0, opts );
82+
83+
var y;
84+
var i;
85+
for ( i = 0; i < x.length; i++ ) {
86+
y = sincosdf( x[ i ] );
87+
console.log( 'sincosdf(%d) = [ %d, %d ]', x[ i ], y[ 0 ], y[ 1 ] );
88+
}
89+
```
90+
91+
</section>
92+
93+
<!-- /.examples -->
94+
95+
<!-- C interface documentation. -->
96+
97+
* * *
98+
99+
<section class="c">
100+
101+
## C APIs
102+
103+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
104+
105+
<section class="intro">
106+
107+
</section>
108+
109+
<!-- /.intro -->
110+
111+
<!-- C usage documentation. -->
112+
113+
<section class="usage">
114+
115+
### Usage
116+
117+
```c
118+
#include "stdlib/math/base/special/sincosdf.h"
119+
```
120+
121+
#### stdlib_base_sincosdf( x, &sine, &cosine )
122+
123+
Simultaneously computes the [sine][@stdlib/math/base/special/sindf] and [cosine][@stdlib/math/base/special/cosdf] of an angle measured in degrees.
124+
125+
```c
126+
float cosine;
127+
float sine;
128+
129+
stdlib_base_sincosdf( 4.0f, &sine, &cosine );
130+
```
131+
132+
The function accepts the following arguments:
133+
134+
- **x**: `[in] float` input value.
135+
- **sine**: `[out] float*` destination for the sine.
136+
- **cosine**: `[out] float*` destination for the cosine.
137+
138+
```c
139+
void stdlib_base_sincosdf( const float x, float *sine, float *cosine );
140+
```
141+
142+
</section>
143+
144+
<!-- /.usage -->
145+
146+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
147+
148+
<section class="notes">
149+
150+
</section>
151+
152+
<!-- /.notes -->
153+
154+
<!-- C API usage examples. -->
155+
156+
<section class="examples">
157+
158+
### Examples
159+
160+
```c
161+
#include "stdlib/math/base/special/sincosdf.h"
162+
#include <stdio.h>
163+
164+
int main( void ) {
165+
const float x[] = { 0.0f, 90.0f, 180.0f, 360.0f };
166+
167+
float cosine;
168+
float sine;
169+
int i;
170+
for ( i = 0; i < 4; i++ ) {
171+
stdlib_base_sincosdf( x[ i ], &sine, &cosine );
172+
printf( "x: %f => sine: %f, cosine: %f\n", x[ i ], sine, cosine );
173+
}
174+
}
175+
```
176+
177+
</section>
178+
179+
<!-- /.examples -->
180+
181+
</section>
182+
183+
<!-- /.c -->
184+
185+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
186+
187+
<section class="related">
188+
189+
</section>
190+
191+
<!-- /.related -->
192+
193+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
194+
195+
<section class="links">
196+
197+
[@stdlib/math/base/special/cosdf]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/cosdf
198+
199+
[@stdlib/math/base/special/sindf]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/sindf
200+
201+
<!-- <related-links> -->
202+
203+
<!-- </related-links> -->
204+
205+
</section>
206+
207+
<!-- /.links -->
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
26+
var sindf = require( '@stdlib/math/base/special/sindf' );
27+
var cosdf = require( '@stdlib/math/base/special/cosdf' );
28+
var format = require( '@stdlib/string/format' );
29+
var pkg = require( './../package.json' ).name;
30+
var sincosdf = require( './../lib' );
31+
32+
33+
// MAIN //
34+
35+
bench( pkg, function benchmark( b ) {
36+
var x;
37+
var y;
38+
var i;
39+
40+
x = uniform( 100, -10.0, 10.0, {
41+
'dtype': 'float32'
42+
});
43+
44+
b.tic();
45+
for ( i = 0; i < b.iterations; i++ ) {
46+
y = sincosdf( x[ i%x.length ] );
47+
if ( isnanf( y[0] ) || isnanf( y[1] ) ) {
48+
b.fail( 'should not return NaN' );
49+
}
50+
}
51+
b.toc();
52+
if ( isnanf( y[0] ) || isnanf( y[1] ) ) {
53+
b.fail( 'should not return NaN' );
54+
}
55+
b.pass( 'benchmark finished' );
56+
b.end();
57+
});
58+
59+
bench( format( '%s::separate-evaluation', pkg ), function benchmark( b ) {
60+
var x;
61+
var y;
62+
var i;
63+
64+
x = uniform( 100, -10.0, 10.0, {
65+
'dtype': 'float32'
66+
});
67+
68+
b.tic();
69+
for ( i = 0; i < b.iterations; i++ ) {
70+
y = [
71+
sindf( x[ i%x.length ] ),
72+
cosdf( x[ i%x.length ] )
73+
];
74+
if ( isnanf( y[0] ) || isnanf( y[1] ) ) {
75+
b.fail( 'should not return NaN' );
76+
}
77+
}
78+
b.toc();
79+
if ( isnanf( y[0] ) || isnanf( y[1] ) ) {
80+
b.fail( 'should not return NaN' );
81+
}
82+
b.pass( 'benchmark finished' );
83+
b.end();
84+
});
85+
86+
bench( format( '%s:assign', pkg ), function benchmark( b ) {
87+
var x;
88+
var y;
89+
var i;
90+
91+
x = uniform( 100, -10.0, 10.0, {
92+
'dtype': 'float32'
93+
});
94+
y = [ 0.0, 0.0 ];
95+
96+
b.tic();
97+
for ( i = 0; i < b.iterations; i++ ) {
98+
sincosdf.assign( x[ i%x.length ], y, 1, 0 );
99+
if ( isnanf( y[0] ) || isnanf( y[1] ) ) {
100+
b.fail( 'should not return NaN' );
101+
}
102+
}
103+
b.toc();
104+
if ( isnanf( y[0] ) || isnanf( y[1] ) ) {
105+
b.fail( 'should not return NaN' );
106+
}
107+
b.pass( 'benchmark finished' );
108+
b.end();
109+
});
110+
111+
bench( format( '%s::separate-evaluation,in-place', pkg ), function benchmark( b ) {
112+
var x;
113+
var y;
114+
var i;
115+
116+
x = uniform( 100, -10.0, 10.0, {
117+
'dtype': 'float32'
118+
});
119+
y = [ 0.0, 0.0 ];
120+
121+
b.tic();
122+
for ( i = 0; i < b.iterations; i++ ) {
123+
y[0] = sindf( x[ i%x.length ] );
124+
y[1] = cosdf( x[ i%x.length ] );
125+
if ( isnanf( y[0] ) || isnanf( y[1] ) ) {
126+
b.fail( 'should not return NaN' );
127+
}
128+
}
129+
b.toc();
130+
if ( isnanf( y[0] ) || isnanf( y[1] ) ) {
131+
b.fail( 'should not return NaN' );
132+
}
133+
b.pass( 'benchmark finished' );
134+
b.end();
135+
});

0 commit comments

Comments
 (0)