Skip to content

Commit 2329ce4

Browse files
committed
feat: add math/base/special/sind
1 parent e3843f1 commit 2329ce4

35 files changed

+1485
-293
lines changed

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

Lines changed: 105 additions & 24 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) 2024 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,9 +18,13 @@ limitations under the License.
1818
1919
-->
2020

21-
# Sine
21+
# sind
2222

23-
> Compute the [sine][sine] of a number.
23+
> Computes the [sine][trigonometric-functions] of an angle measured in degrees, for a double-precision floating-point number.
24+
25+
<section class="intro">
26+
27+
</section>
2428

2529
<section class="usage">
2630

@@ -32,17 +36,20 @@ var sind = require( '@stdlib/math/base/special/sind' );
3236

3337
#### sind( x )
3438

35-
Computes the [sine][sine] of a `number` (in degress).
39+
Computes the [sine][trigonometric-functions] of an angle measured in degrees, for a double-precision floating-point number.
3640

3741
```javascript
3842
var v = sind( 0.0 );
39-
// returns ~0.0
43+
// returns 0.0
44+
45+
v = sind( 30.0 );
46+
// returns 0.5
4047

41-
v = sind( 90 );
42-
// returns ~1.0
48+
v = sind( 90.0 );
49+
// returns 1.0
4350

44-
v = sind( -30 );
45-
// returns ~-0.5
51+
v = sind( NaN );
52+
// returns NaN
4653
```
4754

4855
</section>
@@ -59,7 +66,7 @@ v = sind( -30 );
5966
var linspace = require( '@stdlib/array/base/linspace' );
6067
var sind = require( '@stdlib/math/base/special/sind' );
6168

62-
var x = linspace( 0.0, 360, 555 );
69+
var x = linspace( -180, 180, 100 );
6370

6471
var i;
6572
for ( i = 0; i < x.length; i++ ) {
@@ -71,17 +78,97 @@ for ( i = 0; i < x.length; i++ ) {
7178

7279
<!-- /.examples -->
7380

74-
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
75-
76-
<section class="related">
81+
<!-- C interface documentation. -->
7782

7883
* * *
7984

80-
## See Also
85+
<section class="c">
86+
87+
## C APIs
88+
89+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
90+
91+
<section class="intro">
92+
93+
</section>
94+
95+
<!-- /.intro -->
96+
97+
<!-- C usage documentation. -->
98+
99+
<section class="usage">
100+
101+
### Usage
102+
103+
```c
104+
#include "stdlib/math/base/special/sind.h"
105+
```
81106

82-
- <span class="package-name">[`@stdlib/math/base/special/cos`][@stdlib/math/base/special/cos]</span><span class="delimiter">: </span><span class="description">compute the cosine of a number.</span>
83-
- <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>
84-
- <span class="package-name">[`@stdlib/math/base/special/tan`][@stdlib/math/base/special/tan]</span><span class="delimiter">: </span><span class="description">evaluate the tangent of a number.</span>
107+
#### stdlib_base_sind( x )
108+
109+
Computes the [sine][trigonometric-functions] of an angle measured in degrees, for a double-precision floating-point number.
110+
111+
```c
112+
double out = stdlib_base_sind( 0.0 );
113+
// returns 0.0
114+
115+
out = stdlib_base_sind( 30.0 );
116+
// returns 0.5
117+
```
118+
119+
The function accepts the following arguments:
120+
121+
- **x**: `[in] double` input value.
122+
123+
```c
124+
double stdlib_base_sind( const double x );
125+
```
126+
127+
</section>
128+
129+
<!-- /.usage -->
130+
131+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
132+
133+
<section class="notes">
134+
135+
</section>
136+
137+
<!-- /.notes -->
138+
139+
<!-- C API usage examples. -->
140+
141+
<section class="examples">
142+
143+
### Examples
144+
145+
```c
146+
#include "stdlib/math/base/special/sind.h"
147+
#include <stdio.h>
148+
149+
int main( void ) {
150+
const double x[] = { 0.0, 30.0, 45.0, 60.0, 90.0 };
151+
152+
double y;
153+
int i;
154+
for ( i = 0; i < 5; i++ ) {
155+
y = stdlib_base_sind( x[ i ] );
156+
printf( "sind(%lf) = %lf\n", x[ i ], y );
157+
}
158+
}
159+
```
160+
161+
</section>
162+
163+
<!-- /.examples -->
164+
165+
</section>
166+
167+
<!-- /.c -->
168+
169+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
170+
171+
<section class="related">
85172

86173
</section>
87174

@@ -91,16 +178,10 @@ for ( i = 0; i < x.length; i++ ) {
91178

92179
<section class="links">
93180

94-
[sine]: https://en.wikipedia.org/wiki/Sine
181+
[trigonometric-functions]: https://en.wikipedia.org/wiki/Trigonometric_functions
95182

96183
<!-- <related-links> -->
97184

98-
[@stdlib/math/base/special/cos]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/cos
99-
100-
[@stdlib/math/base/special/sin]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/sin
101-
102-
[@stdlib/math/base/special/tan]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/tan
103-
104185
<!-- </related-links> -->
105186

106187
</section>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 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 randu = require( '@stdlib/random/array/uniform' );
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var pkg = require( './../package.json' ).name;
27+
var sind = 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 = randu( 100, -5.0, 5.0 );
38+
39+
b.tic();
40+
for ( i = 0; i < b.iterations; i++ ) {
41+
y = sind( x[ i % x.length ] );
42+
if ( isnan( y ) ) {
43+
b.fail( 'should not return NaN' );
44+
}
45+
}
46+
b.toc();
47+
if ( isnan( y ) ) {
48+
b.fail( 'should not return NaN' );
49+
}
50+
b.pass( 'benchmark finished' );
51+
b.end();
52+
});
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 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 randu = require( '@stdlib/random/array/uniform' );
26+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
27+
var tryRequire = require( '@stdlib/utils/try-require' );
28+
var pkg = require( './../package.json' ).name;
29+
30+
31+
// VARIABLES //
32+
33+
var sind = tryRequire( resolve( __dirname, './../lib/native.js' ) );
34+
var opts = {
35+
'skip': ( sind 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 = randu( 100, -5.0, 5.0 );
47+
48+
b.tic();
49+
for ( i = 0; i < b.iterations; i++ ) {
50+
y = sind( x[ i % x.length ] );
51+
if ( isnan( y ) ) {
52+
b.fail( 'should not return NaN' );
53+
}
54+
}
55+
b.toc();
56+
if ( isnan( y ) ) {
57+
b.fail( 'should not return NaN' );
58+
}
59+
b.pass( 'benchmark finished' );
60+
b.end();
61+
});

0 commit comments

Comments
 (0)