Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/sind/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<!--

@license Apache-2.0

Copyright (c) 2018 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

# Sine

> Compute the [sine][sine] of a number.

<section class="usage">

## Usage

```javascript
var sin = require( '@stdlib/math/base/special/sin' );
```

#### sin( x )

Computes the [sine][sine] of a `number` (in radians).

```javascript
var v = sin( 0.0 );
// returns ~0.0

v = sin( 3.141592653589793/2.0 );
// returns ~1.0

v = sin( -3.141592653589793/6.0 );
// returns ~-0.5
```

</section>

<!-- /.usage -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var linspace = require( '@stdlib/array/base/linspace' );
var TWO_PI = require( '@stdlib/constants/float64/two-pi' );
var sin = require( '@stdlib/math/base/special/sin' );

var x = linspace( 0.0, TWO_PI, 100 );

var i;
for ( i = 0; i < x.length; i++ ) {
console.log( sin( x[ i ] ) );
}
```

</section>

<!-- /.examples -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

* * *

## See Also

- <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>
- <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>
- <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>

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[sine]: https://en.wikipedia.org/wiki/Sine

<!-- <related-links> -->

[@stdlib/math/base/special/cos]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/cos

[@stdlib/math/base/special/sinpi]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/sinpi

[@stdlib/math/base/special/tan]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/tan

<!-- </related-links> -->

</section>

<!-- /.links -->
28 changes: 28 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/sind/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

{{alias}}( x )
Computes the sine of a number.

Parameters
----------
x: number
Input value (in degrees).

Returns
-------
y: number
Sine.

Examples
--------
> var y = {{alias}}( 0.0 )
~0.0
> y = {{alias}}( 90 )
~1.0
> y = {{alias}}( -30 )
~-0.5
> y = {{alias}}( NaN )
NaN

See Also
--------

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2019 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// TypeScript Version: 2.0

/**
* Computes the sine of a number.
*
* @param x - input value (in degrees)
* @returns sine
*
* @example
* var v = sind( 0.0 );
* // returns ~0.0
*
* @example
* var v = sind( 90 );
* // returns ~1.0
*
* @example
* var v = sind( -30 );
* // returns ~-0.5
*
* @example
* var v = sind( NaN );
* // returns NaN
*/
declare function sind( x: number ): number;


// EXPORTS //

export = sind;
44 changes: 44 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/sind/docs/types/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2019 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import sind = require( './index' );


// TESTS //

// The function returns a number...
{
sind( 8 ); // $ExpectType number
}

// The function does not compile if provided a value other than a number...
{
sind( true ); // $ExpectError
sind( false ); // $ExpectError
sind( null ); // $ExpectError
sind( undefined ); // $ExpectError
sind( '5' ); // $ExpectError
sind( [] ); // $ExpectError
sind( {} ); // $ExpectError
sind( ( x: number ): number => x ); // $ExpectError
}

// The function does not compile if provided insufficient arguments...
{
sind(); // $ExpectError
}
29 changes: 29 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/sind/examples/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

var linspace = require( '@stdlib/array/base/linspace' );
var sind = require( './../lib' );

var x = linspace( 0, 30, -90 );

var i;
for ( i = 0; i < x.length; i++ ) {
console.log( 'sind(%d) = %d', x[ i ], sind( x[ i ] ) );
}
49 changes: 49 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/sind/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

/**
* Compute the sine of a number.
*
* @module @stdlib/math/base/special/sind
*
* @example
* var sind = require( '@stdlib/math/base/special/sind' );
*
* var v = sind( 0.0 );
* // returns ~0.0
*
* v = sind( 90 );
* // returns ~1.0
*
* v = sind( -30 );
* // returns ~-0.5
*
* v = sind( NaN );
* // returns NaN
*/

// MODULES //

var sind = require( './sind.js' );


// EXPORTS //

module.exports = sind;
86 changes: 86 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/sind/lib/sind.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var isnan = require('@stdlib/math/base/assert/is-nan');
var isinfinite = require('@stdlib/math/base/assert/is-infinite');
var abs = require('@stdlib/math/base/special/abs');
var kernelSin = require('@stdlib/math/base/special/kernel-sin');
var kernelCos = require('@stdlib/math/base/special/kernel-cos');
var PI = require('@stdlib/constants/float64/pi');

/**
* Compute the sine of a number.
*
* @module @stdlib/math/base/special/sind
*
* @example
* var sind = require( '@stdlib/math/base/special/sind' );
*
* var v = sind( 0.0 );
* // returns ~0.0
*
* v = sind( 90 );
* // returns ~1.0
*
* v = sind( -30 );
* // returns ~-0.5
*
* v = sind( NaN );
* // returns NaN
*/

function deg2rad(x) {
return (x * PI) / 180;
}

function sind(x) {
if (isinfinite(x)) {
return NaN;
}
if (isnan(x)) {
return NaN;
}
var rad;
x = ((x % 360) + 360) % 360
if (x <= 45) {
rad = deg2rad(x);
return kernelSin(rad, 0);
}
if (x <= 135) {
rad = deg2rad(x - 90);
return kernelCos(rad, 0);
}
if (x <= 225) {
rad = deg2rad(180 - x);
return kernelSin(rad, 0);
}
if (x <= 315) {
rad = deg2rad(x - 270);
return -kernelCos(rad, 0);
}
rad = deg2rad(360 - x)
return -kernelSin(rad, 0);
}

// EXPORTS //

module.exports = sind;
Loading