-
-
Notifications
You must be signed in to change notification settings - Fork 907
feat: add math/base/special/sind
#487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
23c7c53
sind impl from kernel sin and cos
AlisaLC 4dee5d5
removed console log in sind
AlisaLC 2302838
updated tests and docs and changed deg2rad impl
AlisaLC 1912c65
removed extra tests in sind
AlisaLC e3843f1
Merge remote-tracking branch 'upstream/develop' into sind-impl
stdlib-bot 2329ce4
feat: add math/base/special/sind
gunjjoshi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
lib/node_modules/@stdlib/math/base/special/sind/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
28
lib/node_modules/@stdlib/math/base/special/sind/docs/repl.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
-------- | ||
|
48 changes: 48 additions & 0 deletions
48
lib/node_modules/@stdlib/math/base/special/sind/docs/types/index.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
44
lib/node_modules/@stdlib/math/base/special/sind/docs/types/test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
29
lib/node_modules/@stdlib/math/base/special/sind/examples/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
49
lib/node_modules/@stdlib/math/base/special/sind/lib/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
86
lib/node_modules/@stdlib/math/base/special/sind/lib/sind.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
kgryte marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
return (x * PI) / 180; | ||
} | ||
|
||
function sind(x) { | ||
kgryte marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.