Skip to content

Commit 0a59c83

Browse files
feat: add math/base/special/sindf
PR-URL: #7808 Ref: #649 Co-authored-by: Philipp Burckhardt <[email protected]> Reviewed-by: Philipp Burckhardt <[email protected]> Signed-off-by: Karan Anand <[email protected]>
1 parent 09dece9 commit 0a59c83

File tree

28 files changed

+2059
-0
lines changed

28 files changed

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

0 commit comments

Comments
 (0)