UNPKG

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