forked from stdlib-js/stdlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a712830
commit 98b2e60
Showing
15 changed files
with
666 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,76 @@ | ||
<!-- | ||
@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. | ||
--> | ||
|
||
# Secant | ||
|
||
> Compute the [secant][secant] of a number. | ||
<section class="usage"> | ||
|
||
## Usage | ||
|
||
```javascript | ||
var sec = require( '@stdlib/math/base/special/sec' ); | ||
``` | ||
|
||
#### sec( x ) | ||
|
||
Computes the [secant][secant] of a `number` (in radians). | ||
|
||
```javascript | ||
var v = sec( 0.0 ); | ||
// returns 1.0 | ||
|
||
v = sec( 3.141592653589793/4.0 ); | ||
// returns ~1.4144 | ||
|
||
v = sec( -3.141592653589793/6.0 ); | ||
// returns ~1.1547 | ||
|
||
v = sec( NaN ); | ||
// returns NaN | ||
``` | ||
|
||
</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 sec = require( '@stdlib/math/base/special/sec' ); | ||
|
||
var x = linspace( 0.0, TWO_PI, 100 ); | ||
|
||
var i; | ||
for ( i = 0; i < x.length; i++ ) { | ||
console.log( sec( x[ i ] ) ); | ||
} | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.examples --> |
72 changes: 72 additions & 0 deletions
72
lib/node_modules/@stdlib/math/base/special/sec/benchmark/benchmark.js
This file contains 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,72 @@ | ||
/** | ||
* @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 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 sec = 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 = sec( 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 / Math.cos( x ); // eslint-disable-line stdlib/no-builtin-math | ||
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(); | ||
}); |
30 changes: 30 additions & 0 deletions
30
lib/node_modules/@stdlib/math/base/special/sec/examples/index.js
This file contains 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,30 @@ | ||
/** | ||
* @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 TWO_PI = require( '@stdlib/constants/float64/two-pi' ); | ||
var sec = require( './../lib' ); | ||
|
||
var x = linspace( 0.0, TWO_PI, 100 ); | ||
|
||
var i; | ||
for ( i = 0; i < x.length; i++ ) { | ||
console.log( 'sec(%d) = %d', x[ i ], sec( x[ i ] ) ); | ||
} |
46 changes: 46 additions & 0 deletions
46
lib/node_modules/@stdlib/math/base/special/sec/lib/index.js
This file contains 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,46 @@ | ||
/** | ||
* @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 secant of a number. | ||
* | ||
* @module @stdlib/math/base/special/sec | ||
* | ||
* @example | ||
* var sec = require( '@stdlib/math/base/special/sec' ); | ||
* | ||
* var v = sec( 0.0 ); | ||
* // returns 1.0 | ||
* | ||
* v = sec( 3.141592653589793/4.0 ); | ||
* // returns ~1.4144 | ||
* | ||
* v = sec( -3.141592653589793/6.0 ); | ||
* // returns ~1.1547 | ||
*/ | ||
|
||
// MODULES // | ||
|
||
var sec = require( './sec.js' ); | ||
|
||
|
||
// EXPORTS // | ||
|
||
module.exports = sec; |
This file contains 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,69 @@ | ||
/** | ||
* @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. | ||
* | ||
* | ||
* ## Notice | ||
* | ||
* The following copyright, license, and long comment were part of the original implementation available as part of [FreeBSD]{@link https://svnweb.freebsd.org/base/release/9.3.0/lib/msun/src/s_cos.c}. The implementation follows the original, but has been modified for JavaScript. | ||
* | ||
* ```text | ||
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | ||
* | ||
* Developed at SunPro, a Sun Microsystems, Inc. business. | ||
* Permission to use, copy, modify, and distribute this | ||
* software is freely granted, provided that this notice | ||
* is preserved. | ||
* ``` | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// MODULES // | ||
var cos = require('@stdlib/math/base/special/cos/lib'); | ||
|
||
// MAIN // | ||
|
||
/** | ||
* Computes the secant of a number. | ||
* | ||
* @param {number} x - input value (in radians) | ||
* @returns {number} secant | ||
* | ||
* @example | ||
* var v = sec( 0.0 ); | ||
* // returns 1.0 | ||
* | ||
* @example | ||
* var v = sec( 3.141592653589793/4.0 ); | ||
* // returns ~1.4144 | ||
* | ||
* @example | ||
* var v = sec( -3.141592653589793/6.0 ); | ||
* // returns ~1.1547 | ||
* | ||
* @example | ||
* var v = sec( NaN ); | ||
* // returns NaN | ||
*/ | ||
function sec( x ) { | ||
return 1 / cos(x); | ||
} | ||
|
||
|
||
// EXPORTS // | ||
|
||
module.exports = sec; |
64 changes: 64 additions & 0 deletions
64
lib/node_modules/@stdlib/math/base/special/sec/package.json
This file contains 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,64 @@ | ||
{ | ||
"name": "@stdlib/math/base/special/cos", | ||
"version": "0.0.0", | ||
"description": "Compute the cosine of a number.", | ||
"license": "Apache-2.0", | ||
"author": { | ||
"name": "The Stdlib Authors", | ||
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors" | ||
}, | ||
"contributors": [ | ||
{ | ||
"name": "The Stdlib Authors", | ||
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors" | ||
} | ||
], | ||
"main": "./lib", | ||
"directories": { | ||
"benchmark": "./benchmark", | ||
"doc": "./docs", | ||
"example": "./examples", | ||
"lib": "./lib", | ||
"scripts": "./scripts", | ||
"test": "./test" | ||
}, | ||
"types": "./docs/types", | ||
"scripts": {}, | ||
"homepage": "https://github.com/stdlib-js/stdlib", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/stdlib-js/stdlib.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/stdlib-js/stdlib/issues" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": {}, | ||
"engines": { | ||
"node": ">=0.10.0", | ||
"npm": ">2.7.0" | ||
}, | ||
"os": [ | ||
"aix", | ||
"darwin", | ||
"freebsd", | ||
"linux", | ||
"macos", | ||
"openbsd", | ||
"sunos", | ||
"win32", | ||
"windows" | ||
], | ||
"keywords": [ | ||
"stdlib", | ||
"stdmath", | ||
"mathematics", | ||
"math", | ||
"math.cos", | ||
"cos", | ||
"cosine", | ||
"trig", | ||
"trigonometry", | ||
"radians" | ||
] | ||
} |
2 changes: 2 additions & 0 deletions
2
lib/node_modules/@stdlib/math/base/special/sec/test/fixtures/julia/REQUIRE
This file contains 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,2 @@ | ||
julia 1.5 | ||
JSON 0.21 |
1 change: 1 addition & 0 deletions
1
lib/node_modules/@stdlib/math/base/special/sec/test/fixtures/julia/huge_negative.json
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
lib/node_modules/@stdlib/math/base/special/sec/test/fixtures/julia/huge_positive.json
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
lib/node_modules/@stdlib/math/base/special/sec/test/fixtures/julia/large_negative.json
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
lib/node_modules/@stdlib/math/base/special/sec/test/fixtures/julia/large_positive.json
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
lib/node_modules/@stdlib/math/base/special/sec/test/fixtures/julia/medium_negative.json
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
lib/node_modules/@stdlib/math/base/special/sec/test/fixtures/julia/medium_positive.json
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.