Skip to content

Commit 3bd783f

Browse files
committed
cosc
1 parent 1f27ffe commit 3bd783f

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var sinpi = require( '@stdlib/math/base/special/sinpi' );
24+
var cospi=require('@stdlib/math/base/special/cospi');
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var isInfinite = require( '@stdlib/math/base/assert/is-infinite' );
27+
var PI = require( '@stdlib/constants/float64/pi' );
28+
29+
30+
// MAIN //
31+
32+
/**
33+
* Computes the normalized derivative of cardinal sine of a number.
34+
*
35+
* ## Method
36+
*
37+
* For \\( x \neq 0 \\), the normalized derivative of cardinal sine is calculated as
38+
*
39+
* ```tex
40+
* \operatorname{cosc}(x) = \frac{{\operatorname{cos}(\pi x)}-\frac{\operatorname{sin}(\pi x)}{\pi x}}{x}.
41+
* ```
42+
*
43+
* ## Special Cases
44+
*
45+
* ```tex
46+
* \begin{align*}
47+
* \operatorname{cosc}(0) &= 0 & \\
48+
* \operatorname{cosc}(\infty) &= 0 & \\
49+
* \operatorname{cosc}(-\infty) &= 0 & \\
50+
* \operatorname{cosc}(\mathrm{NaN}) &= \mathrm{NaN}
51+
* \end{align*}
52+
* ```
53+
*
54+
* @param {number} x - input value
55+
* @returns {number} derivative of cardinal sine
56+
*
57+
* @example
58+
* var v = cosc( 0.5 );
59+
* // returns ~-1.273
60+
*
61+
* @example
62+
* var v = cosc( -1.2 );
63+
* // returns ~-0.544
64+
*
65+
* @example
66+
* var v = cosc( 0.0 );
67+
* // returns 0.0
68+
*
69+
* @example
70+
* var v = cosc( NaN );
71+
* // returns NaN
72+
*/
73+
function cosc( x ) {
74+
if ( isnan( x ) ) {
75+
return NaN;
76+
}
77+
if ( isInfinite( x ) ) {
78+
return 0.0;
79+
}
80+
if ( x === 0.0 ) {
81+
return 0.0;
82+
}
83+
return (cospi( x ) - (sinpi( x )/(PI*x))) / x;
84+
}
85+
86+
87+
// EXPORTS //
88+
89+
module.exports = cosc;
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var addon = require( './../src/addon.node' );
24+
25+
26+
// MAIN //
27+
28+
/**
29+
* Computes the normalized derivative of cardinal sine of a number.
30+
*
31+
* @private
32+
* @param {number} x - input value
33+
* @returns {number} derivative of cardinal sine
34+
*
35+
* @example
36+
* var v = cosc( 0.5 );
37+
* // returns ~-1.273
38+
*
39+
* @example
40+
* var v = cosc( -1.2 );
41+
* // returns ~0.544
42+
*
43+
* @example
44+
* var v = cosc( 0.0 );
45+
* // returns 0.0
46+
*
47+
* @example
48+
* var v = cosc( NaN );
49+
* // returns NaN
50+
*/
51+
function cosc( x ) {
52+
return addon( x );
53+
}
54+
55+
56+
// EXPORTS //
57+
58+
module.exports = cosc;

0 commit comments

Comments
 (0)