Skip to content

Commit

Permalink
feat: add math/base/special/acscd
Browse files Browse the repository at this point in the history
PR-URL: stdlib-js#1789
Closes: stdlib-js#42

---------

Signed-off-by: Sai Srikar Dumpeti <80447788+the-r3aper7@users.noreply.github.com>
Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com>
  • Loading branch information
the-r3aper7 authored Mar 12, 2024
1 parent 7489261 commit 1d7b726
Show file tree
Hide file tree
Showing 14 changed files with 696 additions and 0 deletions.
104 changes: 104 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/acscd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<!--
@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.
-->

# acscd

> Compute the [arccosecant][arccosecant] in degrees of a double-precision floating-point number.
<section class="usage">

## Usage

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

#### acscd( x )

Computes the [arccosecant][arccosecant] (in degrees) of a double-precision floating-point number.

```javascript
var sqrt = require( '@stdlib/math/base/special/sqrt' );
var v = acscd( Infinity );
// returns 0.0

v = acscd( 2 * sqrt( 3 ) / 3 );
// returns ~60.0

v = acscd( sqrt( 2 ) );
// returns ~45.0

v = acscd( 2 );
// returns ~30.0

v = acscd( 1 );
// returns 90.0

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

</section>

<!-- /.usage -->

<section class="examples">

## Examples

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

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

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

var i;
for ( i = 0; i < x.length; i++ ) {
console.log( acscd( 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">

[arccosecant]: https://en.wikipedia.org/wiki/Inverse_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 acscd = 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()*2.0 ) + 1.0;
y = acscd( 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();
});
31 changes: 31 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/acscd/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

{{alias}}( x )
Computes the arccosecant of (in degrees) a double-precision floating-point
number.

If `x` does not satisy `x >= 1` or `x <= -1`, the function returns NaN.

Parameters
----------
x: number
Input value.

Returns
-------
y: number
Arccosecant (in degrees).

Examples
--------
> var y = {{alias}}( 0.0 )
NaN
> y = {{alias}}( {{alias:@stdlib/constants/float64/pi}}/6.0 )
NaN
> y = {{alias}}( 1 )
90.0
> y = {{alias}}( NaN )
NaN

See Also
--------

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* @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 arccosecant (in degrees) of a double-precision floating-point number.
*
* @param x - input value
* @returns arccosecant (in degrees)
*
* @example
* var v = acscd( Infinity );
* // returns 0.0
*
* @example
* var v = acscd( 2 * Math.sqrt( 3 ) / 3 );
* // returns ~60.0
*
* @example
* var v = acscd( Math.sqrt( 2 ) );
* // returns ~45.0
*
* @example
* var v = acscd( 2 );
* // returns ~30.0
*
* @example
* var v = acscd( 1 );
* // returns 90.0
*
* @example
* var v = acscd( NaN );
* // returns NaN
*/
declare function acscd( x: number ): number;


// EXPORTS //

export = acscd;
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 acscd = require( './index' );


// TESTS //

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

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

// The compiler throws an error if the function is provided insufficient arguments...
{
acscd(); // $ExpectError
}
29 changes: 29 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/acscd/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 acscd = require( './../lib' );

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

var i;
for ( i = 0; i < x.length; i++ ) {
console.log( 'acscd(%d) = %d', x[ i ], acscd( x[ i ] ) );
}
55 changes: 55 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/acscd/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* @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 arccosecant (in degrees) of a double-precision floating-point number.
*
* @module @stdlib/math/base/special/acscd
*
* @example
* var acscd = require( '@stdlib/math/base/special/acscd' );
*
* var v = acscd( Infinity );
* // returns 0.0
*
* v = acscd( 2 * Math.sqrt(3) / 3 );
* // returns ~60.0
*
* v = acscd( Math.sqrt(2) );
* // returns ~45.0
*
* v = acscd( 2 );
* // returns ~30.0
*
* v = acscd( 1 );
* // returns 90.0
*
* v = acscd( NaN );
* // returns NaN
*/

// MODULES //

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


// EXPORTS //

module.exports = main;
Loading

0 comments on commit 1d7b726

Please sign in to comment.