UNPKG

1.28 kBJavaScriptView Raw
1'use strict'
2
3const deepMap = require('../../utils/collection/deepMap')
4
5function factory (type, config, load, typed) {
6 /**
7 * Calculate the inverse secant of a value. Defined as `asec(x) = acos(1/x)`.
8 *
9 * For matrices, the function is evaluated element wise.
10 *
11 * Syntax:
12 *
13 * math.asec(x)
14 *
15 * Examples:
16 *
17 * math.asec(0.5) // returns 1.0471975511965979
18 * math.asec(math.sec(1.5)) // returns 1.5
19 *
20 * math.asec(2) // returns 0 + 1.3169578969248166 i
21 *
22 * See also:
23 *
24 * acos, acot, acsc
25 *
26 * @param {number | Complex | Array | Matrix} x Function input
27 * @return {number | Complex | Array | Matrix} The arc secant of x
28 */
29 const asec = typed('asec', {
30 'number': function (x) {
31 if (x <= -1 || x >= 1 || config.predictable) {
32 return Math.acos(1 / x)
33 }
34 return new type.Complex(x, 0).asec()
35 },
36
37 'Complex': function (x) {
38 return x.asec()
39 },
40
41 'BigNumber': function (x) {
42 return new type.BigNumber(1).div(x).acos()
43 },
44
45 'Array | Matrix': function (x) {
46 return deepMap(x, asec)
47 }
48 })
49
50 asec.toTex = { 1: `\\sec^{-1}\\left(\${args[0]}\\right)` }
51
52 return asec
53}
54
55exports.name = 'asec'
56exports.factory = factory