UNPKG

1.27 kBJavaScriptView Raw
1'use strict'
2
3const deepMap = require('../../utils/collection/deepMap')
4
5function factory (type, config, load, typed) {
6 /**
7 * Calculate the cosecant of a value, defined as `csc(x) = 1/sin(x)`.
8 *
9 * For matrices, the function is evaluated element wise.
10 *
11 * Syntax:
12 *
13 * math.csc(x)
14 *
15 * Examples:
16 *
17 * math.csc(2) // returns number 1.099750170294617
18 * 1 / math.sin(2) // returns number 1.099750170294617
19 *
20 * See also:
21 *
22 * sin, sec, cot
23 *
24 * @param {number | Complex | Unit | Array | Matrix} x Function input
25 * @return {number | Complex | Array | Matrix} Cosecant of x
26 */
27 const csc = typed('csc', {
28 'number': function (x) {
29 return 1 / Math.sin(x)
30 },
31
32 'Complex': function (x) {
33 return x.csc()
34 },
35
36 'BigNumber': function (x) {
37 return new type.BigNumber(1).div(x.sin())
38 },
39
40 'Unit': function (x) {
41 if (!x.hasBase(type.Unit.BASE_UNITS.ANGLE)) {
42 throw new TypeError('Unit in function csc is no angle')
43 }
44 return csc(x.value)
45 },
46
47 'Array | Matrix': function (x) {
48 return deepMap(x, csc)
49 }
50 })
51
52 csc.toTex = { 1: `\\csc\\left(\${args[0]}\\right)` }
53
54 return csc
55}
56
57exports.name = 'csc'
58exports.factory = factory