UNPKG

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