Skip to content

Commit

Permalink
feat: add math/base/special/cosd
Browse files Browse the repository at this point in the history
PR-URL: #1777
Closes: #33

---------

Signed-off-by: Sai Srikar Dumpeti <80447788+the-r3aper7@users.noreply.github.com>
Signed-off-by: Philipp Burckhardt <pburckhardt@outlook.com>
Co-authored-by: Philipp Burckhardt <pburckhardt@outlook.com>
Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com>
  • Loading branch information
the-r3aper7 and Planeshifter authored Mar 17, 2024
1 parent 5b5ce15 commit 0b0e240
Show file tree
Hide file tree
Showing 14 changed files with 673 additions and 0 deletions.
101 changes: 101 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/cosd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<!--
@license Apache-2.0
Copyright (c) 2024 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.
-->

# cosd

> Computes the [cosine][trigonometric-functions] of an angle measured in degrees.
<section class="intro">

</section>

<section class="usage">

## Usage

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

#### cosd( x )

Computes the [cosine][trigonometric-functions] of `x` (in degrees).

```javascript
var v = cosd( 0.0 );
// returns 1.0

v = cosd( 60.0 );
// returns ~0.5

v = cosd( 90.0 );
// returns 0.0

v = cosd( NaN );
// returns NaN
```

</section>

<!-- /.usage -->

<section class="examples">

## Examples

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

```javascript
var linspace = require( '@stdlib/array/base/linspace' );
var cosd = require( '@stdlib/math/base/special/cosd' );

var x = linspace( -180, 180, 100 );

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

</section>

<!-- /.examples -->

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

<section class="related">

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

[trigonometric-functions]: https://en.wikipedia.org/wiki/Trigonometric_functions

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

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

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 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 bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var cosd = require( './../lib' );


// MAIN //

bench( pkg, function benchmark( b ) {
var x;
var y;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*10.0 ) - 5.0;
y = cosd( x );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});
28 changes: 28 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/cosd/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

{{alias}}( x )
Computes the cosine of an angle measured in degrees.

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

Returns
-------
y: number
Cosine.

Examples
--------
> var y = {{alias}}( 0.0 )
1.0
> y = {{alias}}( 90.0 )
0.0
> y = {{alias}}( 60.0 )
~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) 2024 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: 4.1

/**
* Computes the cosine of an angle measured in degrees.
*
* @param x - input value (in degrees)
* @returns cosine
*
* @example
* var v = cosd( 0.0 );
* // returns 1.0
*
* @example
* var v = cosd( 60.0 );
* // returns ~0.5
*
* @example
* var v = cosd( 90.0);
* // returns 0
*
* @example
* var v = cosd( NaN );
* // returns NaN
*/
declare function cosd( x: number ): number;


// EXPORTS //

export = cosd;
44 changes: 44 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/cosd/docs/types/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2024 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 cosd = require( './index' );


// TESTS //

// The function returns a number...
{
cosd( 60.0 ); // $ExpectType number
}

// The compiler throws an error if the function is provided a value other than a number...
{
cosd( true ); // $ExpectError
cosd( false ); // $ExpectError
cosd( null ); // $ExpectError
cosd( undefined ); // $ExpectError
cosd( '5' ); // $ExpectError
cosd( [] ); // $ExpectError
cosd( {} ); // $ExpectError
cosd( ( x: number ): number => x ); // $ExpectError
}

// The compiler throws an error if the function is provided insufficient arguments...
{
cosd(); // $ExpectError
}
29 changes: 29 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/cosd/examples/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 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 cosd = require( './../lib' );

var x = linspace( -180, 180, 100 );

var i;
for ( i = 0; i < x.length; i++ ) {
console.log( 'cosd(%d) = %d', x[ i ], cosd( x[ i ] ) );
}
49 changes: 49 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/cosd/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 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 cosine of an angle measured in degrees.
*
* @module @stdlib/math/base/special/cosd
*
* @example
* var cosd = require( '@stdlib/math/base/special/cosd' );
*
* var v = cosd( 0.0 );
* // returns 1.0
*
* v = cosd( 90.0 );
* // returns 0.0
*
* v = cosd( 60.0 );
* // returns ~0.5
*
* v = cosd( NaN );
* // returns NaN
*/

// MODULES //

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


// EXPORTS //

module.exports = main;
Loading

1 comment on commit 0b0e240

@stdlib-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage Report

Package Statements Branches Functions Lines
math/base/special/cosd $\color{red}119/121$
$\color{green}+98.35\%$
$\color{red}6/7$
$\color{green}+85.71\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{red}119/121$
$\color{green}+98.35\%$

The above coverage report was generated for the changes in this push.

Please sign in to comment.