UNPKG

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