UNPKG

1.28 kBJavaScriptView Raw
1import { factory } from '../../utils/factory'
2import { deepMap } from '../../utils/collection'
3import { cscNumber } from '../../plain/number'
4
5const name = 'csc'
6const dependencies = ['typed', 'BigNumber']
7
8export const createCsc = /* #__PURE__ */ factory(name, dependencies, ({ typed, BigNumber }) => {
9 /**
10 * Calculate the cosecant of a value, defined as `csc(x) = 1/sin(x)`.
11 *
12 * For matrices, the function is evaluated element wise.
13 *
14 * Syntax:
15 *
16 * math.csc(x)
17 *
18 * Examples:
19 *
20 * math.csc(2) // returns number 1.099750170294617
21 * 1 / math.sin(2) // returns number 1.099750170294617
22 *
23 * See also:
24 *
25 * sin, sec, cot
26 *
27 * @param {number | Complex | Unit | Array | Matrix} x Function input
28 * @return {number | Complex | Array | Matrix} Cosecant of x
29 */
30 return typed(name, {
31 number: cscNumber,
32
33 Complex: function (x) {
34 return x.csc()
35 },
36
37 BigNumber: function (x) {
38 return new BigNumber(1).div(x.sin())
39 },
40
41 Unit: function (x) {
42 if (!x.hasBase(x.constructor.BASE_UNITS.ANGLE)) {
43 throw new TypeError('Unit in function csc is no angle')
44 }
45 return this(x.value)
46 },
47
48 'Array | Matrix': function (x) {
49 return deepMap(x, this)
50 }
51 })
52})