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