Skip to content

Commit 23c7c53

Browse files
committed
sind impl from kernel sin and cos
1 parent 7ba8112 commit 23c7c53

File tree

18 files changed

+766
-0
lines changed

18 files changed

+766
-0
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2018 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+
# Sine
22+
23+
> Compute the [sine][sine] of a number.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var sin = require( '@stdlib/math/base/special/sin' );
31+
```
32+
33+
#### sin( x )
34+
35+
Computes the [sine][sine] of a `number` (in radians).
36+
37+
```javascript
38+
var v = sin( 0.0 );
39+
// returns ~0.0
40+
41+
v = sin( 3.141592653589793/2.0 );
42+
// returns ~1.0
43+
44+
v = sin( -3.141592653589793/6.0 );
45+
// returns ~-0.5
46+
```
47+
48+
</section>
49+
50+
<!-- /.usage -->
51+
52+
<section class="examples">
53+
54+
## Examples
55+
56+
<!-- eslint no-undef: "error" -->
57+
58+
```javascript
59+
var linspace = require( '@stdlib/array/base/linspace' );
60+
var TWO_PI = require( '@stdlib/constants/float64/two-pi' );
61+
var sin = require( '@stdlib/math/base/special/sin' );
62+
63+
var x = linspace( 0.0, TWO_PI, 100 );
64+
65+
var i;
66+
for ( i = 0; i < x.length; i++ ) {
67+
console.log( sin( x[ i ] ) );
68+
}
69+
```
70+
71+
</section>
72+
73+
<!-- /.examples -->
74+
75+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
76+
77+
<section class="related">
78+
79+
* * *
80+
81+
## See Also
82+
83+
- <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>
84+
- <span class="package-name">[`@stdlib/math/base/special/sinpi`][@stdlib/math/base/special/sinpi]</span><span class="delimiter">: </span><span class="description">compute sin(πx).</span>
85+
- <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>
86+
87+
</section>
88+
89+
<!-- /.related -->
90+
91+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
92+
93+
<section class="links">
94+
95+
[sine]: https://en.wikipedia.org/wiki/Sine
96+
97+
<!-- <related-links> -->
98+
99+
[@stdlib/math/base/special/cos]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/cos
100+
101+
[@stdlib/math/base/special/sinpi]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/sinpi
102+
103+
[@stdlib/math/base/special/tan]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/tan
104+
105+
<!-- </related-links> -->
106+
107+
</section>
108+
109+
<!-- /.links -->
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
{{alias}}( x )
3+
Computes the sine of a number.
4+
5+
Parameters
6+
----------
7+
x: number
8+
Input value (in degrees).
9+
10+
Returns
11+
-------
12+
y: number
13+
Sine.
14+
15+
Examples
16+
--------
17+
> var y = {{alias}}( 0.0 )
18+
~0.0
19+
> y = {{alias}}( 90 )
20+
~1.0
21+
> y = {{alias}}( -30 )
22+
~-0.5
23+
> y = {{alias}}( NaN )
24+
NaN
25+
26+
See Also
27+
--------
28+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2019 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+
// TypeScript Version: 2.0
20+
21+
/**
22+
* Computes the sine of a number.
23+
*
24+
* @param x - input value (in degrees)
25+
* @returns sine
26+
*
27+
* @example
28+
* var v = sind( 0.0 );
29+
* // returns ~0.0
30+
*
31+
* @example
32+
* var v = sind( 90 );
33+
* // returns ~1.0
34+
*
35+
* @example
36+
* var v = sind( -30 );
37+
* // returns ~-0.5
38+
*
39+
* @example
40+
* var v = sind( NaN );
41+
* // returns NaN
42+
*/
43+
declare function sind( x: number ): number;
44+
45+
46+
// EXPORTS //
47+
48+
export = sind;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2019 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+
import sind = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a number...
25+
{
26+
sind( 8 ); // $ExpectType number
27+
}
28+
29+
// The function does not compile if provided a value other than a number...
30+
{
31+
sind( true ); // $ExpectError
32+
sind( false ); // $ExpectError
33+
sind( null ); // $ExpectError
34+
sind( undefined ); // $ExpectError
35+
sind( '5' ); // $ExpectError
36+
sind( [] ); // $ExpectError
37+
sind( {} ); // $ExpectError
38+
sind( ( x: number ): number => x ); // $ExpectError
39+
}
40+
41+
// The function does not compile if provided insufficient arguments...
42+
{
43+
sind(); // $ExpectError
44+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 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+
var linspace = require( '@stdlib/array/base/linspace' );
22+
var sind = require( './../lib' );
23+
24+
var x = linspace( 0, 30, -90 );
25+
26+
var i;
27+
for ( i = 0; i < x.length; i++ ) {
28+
console.log( 'sind(%d) = %d', x[ i ], sind( x[ i ] ) );
29+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 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+
/**
22+
* Compute the sine of a number.
23+
*
24+
* @module @stdlib/math/base/special/sind
25+
*
26+
* @example
27+
* var sind = require( '@stdlib/math/base/special/sind' );
28+
*
29+
* var v = sind( 0.0 );
30+
* // returns ~0.0
31+
*
32+
* v = sind( 90 );
33+
* // returns ~1.0
34+
*
35+
* v = sind( -30 );
36+
* // returns ~-0.5
37+
*
38+
* v = sind( NaN );
39+
* // returns NaN
40+
*/
41+
42+
// MODULES //
43+
44+
var sind = require( './sind.js' );
45+
46+
47+
// EXPORTS //
48+
49+
module.exports = sind;

0 commit comments

Comments
 (0)