|
| 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; |
0 commit comments