UNPKG

1.53 kBJavaScriptView Raw
1import { factory } from '../../utils/factory';
2import { deepMap } from '../../utils/collection';
3var name = 'cos';
4var dependencies = ['typed'];
5export var createCos =
6/* #__PURE__ */
7factory(name, dependencies, function (_ref) {
8 var typed = _ref.typed;
9
10 /**
11 * Calculate the cosine of a value.
12 *
13 * For matrices, the function is evaluated element wise.
14 *
15 * Syntax:
16 *
17 * math.cos(x)
18 *
19 * Examples:
20 *
21 * math.cos(2) // returns number -0.4161468365471422
22 * math.cos(math.pi / 4) // returns number 0.7071067811865475
23 * math.cos(math.unit(180, 'deg')) // returns number -1
24 * math.cos(math.unit(60, 'deg')) // returns number 0.5
25 *
26 * const angle = 0.2
27 * math.pow(math.sin(angle), 2) + math.pow(math.cos(angle), 2) // returns number ~1
28 *
29 * See also:
30 *
31 * cos, tan
32 *
33 * @param {number | BigNumber | Complex | Unit | Array | Matrix} x Function input
34 * @return {number | BigNumber | Complex | Array | Matrix} Cosine of x
35 */
36 var cos = typed(name, {
37 number: Math.cos,
38 Complex: function Complex(x) {
39 return x.cos();
40 },
41 BigNumber: function BigNumber(x) {
42 return x.cos();
43 },
44 Unit: function Unit(x) {
45 if (!x.hasBase(x.constructor.BASE_UNITS.ANGLE)) {
46 throw new TypeError('Unit in function cos is no angle');
47 }
48
49 return cos(x.value);
50 },
51 'Array | Matrix': function ArrayMatrix(x) {
52 return deepMap(x, cos);
53 }
54 });
55 return cos;
56});
\No newline at end of file