Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Feb 29, 2024
1 parent 16bc470 commit 9519295
Show file tree
Hide file tree
Showing 26 changed files with 1,042 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
# Contributors listed in alphabetical order.

Aditya Sapra <[email protected]>
AgPriyanshu18 <[email protected]>
Ali Salesi <[email protected]>
Amit Jimiwal <[email protected]>
Athan Reines <[email protected]>
Brendan Graetz <[email protected]>
Bruno Fenzl <[email protected]>
Chinmay J <[email protected]>
Christopher Dambamuromo <[email protected]>
Dan Rose <[email protected]>
Daniel Killenberger <[email protected]>
Expand Down Expand Up @@ -36,6 +38,7 @@ Ognjen Jevremović <[email protected]>
Philipp Burckhardt <[email protected]>
Prajwal Kulkarni <[email protected]>
Pranav Goswami <[email protected]>
Praneki <[email protected]>
Pratik <[email protected]>
Ricky Reusser <[email protected]>
Robert Gislason <[email protected]>
Expand All @@ -44,6 +47,7 @@ Rutam <[email protected]>
Ryan Seal <[email protected]>
Seyyed Parsa Neshaei <[email protected]>
Shraddheya Shendre <[email protected]>
Shubham <[email protected]>
Spandan Barve <[email protected]>
Stephannie Jiménez Gacha <[email protected]>
Yernar Yergaziyev <[email protected]>
Expand Down
113 changes: 113 additions & 0 deletions base/special/csc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<!--
@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.
-->

# Cosecant

> Evaluate the [cosecant][trigonometric-functions] of a number.
<section class="intro">

</section>

<section class="usage">

## Usage

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

## csc( x )

Evaluates the [cosecant][trigonometric-functions] of `x` (in radians).

```javascript
var v = csc( 0.0 );
// returns Infinity

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

v = csc( -3.141592653589793/6.0 );
// returns ~-2.0

v = csc( 3.141592653589793/6.0 );
// returns ~2.0

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

</section>

<!-- /.usage -->

<section class="examples">

## Examples

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

```javascript
var linspace = require( '@stdlib/array/base/linspace' );
var PI = require( '@stdlib/constants/float64/pi' );
var csc = require( '@stdlib/math/base/special/csc' );

var x = linspace( -PI/2.0, PI/2.0, 100 );

var i;
for ( i = 0; i < x.length; i++ ) {
console.log( csc( 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/sin`][@stdlib/math/base/special/sin]</span><span class="delimiter">: </span><span class="description">evaluate the sine 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">

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

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

[@stdlib/math/base/special/sin]: https://github.com/stdlib-js/math/tree/main/base/special/sin

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

</section>

<!-- /.links -->
73 changes: 73 additions & 0 deletions base/special/csc/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* @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( './../../../../base/assert/is-nan' );
var sin = require( './../../../../base/special/sin' );
var pkg = require( './../package.json' ).name;
var csc = 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() * 20.0) - 10.0;
y = csc( 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();
});

bench( pkg + '::built-in', function benchmark( b ) {
var x;
var y;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = (randu() * 20.0) - 10.0;
y = 1.0 / sin( 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();
});
27 changes: 27 additions & 0 deletions base/special/csc/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

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

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

Returns
-------
y: number
Cosecant.

Examples
--------
> var y = {{alias}}( 0.0 )
Infinity
> y = {{alias}}( {{alias:@stdlib/constants/float64/pi}}/2.0 )
~1.0
> y = {{alias}}( -{{alias:@stdlib/constants/float64/pi}}/6.0 )
~-2.0
> y = {{alias}}( NaN )
NaN

See Also
--------
48 changes: 48 additions & 0 deletions base/special/csc/docs/types/index.d.ts
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 cosecant of a number.
*
* @param x - input value (in radians)
* @returns cosecant
*
* @example
* var v = csc( 0.0 );
* // returns Infinity
*
* @example
* var v = csc( 3.141592653589793/2.0 );
* // returns ~1.0
*
* @example
* var v = csc( -3.141592653589793/6.0 );
* // returns ~-2.0
*
* @example
* var v = csc( NaN );
* // returns NaN
*/
declare function csc( x: number ): number;


// EXPORTS //

export = csc;
44 changes: 44 additions & 0 deletions base/special/csc/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 csc = require( './index' );


// TESTS //

// The function returns a number...
{
csc( 2 ); // $ExpectType number
}

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

// The compiler throws an error if the function is provided insufficient arguments...
{
csc(); // $ExpectError
}
30 changes: 30 additions & 0 deletions base/special/csc/examples/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* @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 TWO_PI = require( '@stdlib/constants/float64/two-pi' );
var csc = require( './../lib' );

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

var i;
for ( i = 0; i < x.length; i++ ) {
console.log( 'csc(%d) = %d', x[i], csc( x[i] ) );
}
Loading

0 comments on commit 9519295

Please sign in to comment.