UNPKG

1.38 kBJavaScriptView Raw
1import { factory } from '../../utils/factory.js';
2import { deepMap } from '../../utils/collection.js';
3import { cotNumber } from '../../plain/number/index.js';
4var name = 'cot';
5var dependencies = ['typed', 'BigNumber'];
6export var createCot = /* #__PURE__ */factory(name, dependencies, (_ref) => {
7 var {
8 typed,
9 BigNumber: _BigNumber
10 } = _ref;
11
12 /**
13 * Calculate the cotangent of a value. Defined as `cot(x) = 1 / tan(x)`.
14 *
15 * For matrices, the function is evaluated element wise.
16 *
17 * Syntax:
18 *
19 * math.cot(x)
20 *
21 * Examples:
22 *
23 * math.cot(2) // returns number -0.45765755436028577
24 * 1 / math.tan(2) // returns number -0.45765755436028577
25 *
26 * See also:
27 *
28 * tan, sec, csc
29 *
30 * @param {number | Complex | Unit | Array | Matrix} x Function input
31 * @return {number | Complex | Array | Matrix} Cotangent of x
32 */
33 return typed(name, {
34 number: cotNumber,
35 Complex: function Complex(x) {
36 return x.cot();
37 },
38 BigNumber: function BigNumber(x) {
39 return new _BigNumber(1).div(x.tan());
40 },
41 Unit: function Unit(x) {
42 if (!x.hasBase(x.constructor.BASE_UNITS.ANGLE)) {
43 throw new TypeError('Unit in function cot is no angle');
44 }
45
46 return this(x.value);
47 },
48 'Array | Matrix': function ArrayMatrix(x) {
49 return deepMap(x, this);
50 }
51 });
52});
\No newline at end of file