UNPKG

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