UNPKG

1.63 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.createSech = void 0;
7
8var _factory = require("../../utils/factory");
9
10var _collection = require("../../utils/collection");
11
12var _number = require("../../plain/number");
13
14var name = 'sech';
15var dependencies = ['typed', 'BigNumber'];
16var createSech = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
17 var typed = _ref.typed,
18 _BigNumber = _ref.BigNumber;
19
20 /**
21 * Calculate the hyperbolic secant of a value,
22 * defined as `sech(x) = 1 / cosh(x)`.
23 *
24 * For matrices, the function is evaluated element wise.
25 *
26 * Syntax:
27 *
28 * math.sech(x)
29 *
30 * Examples:
31 *
32 * // sech(x) = 1/ cosh(x)
33 * math.sech(0.5) // returns 0.886818883970074
34 * 1 / math.cosh(0.5) // returns 0.886818883970074
35 *
36 * See also:
37 *
38 * cosh, csch, coth
39 *
40 * @param {number | Complex | Unit | Array | Matrix} x Function input
41 * @return {number | Complex | Array | Matrix} Hyperbolic secant of x
42 */
43 var sech = typed(name, {
44 number: _number.sechNumber,
45 Complex: function Complex(x) {
46 return x.sech();
47 },
48 BigNumber: function BigNumber(x) {
49 return new _BigNumber(1).div(x.cosh());
50 },
51 Unit: function Unit(x) {
52 if (!x.hasBase(x.constructor.BASE_UNITS.ANGLE)) {
53 throw new TypeError('Unit in function sech is no angle');
54 }
55
56 return sech(x.value);
57 },
58 'Array | Matrix': function ArrayMatrix(x) {
59 return (0, _collection.deepMap)(x, sech);
60 }
61 });
62 return sech;
63});
64exports.createSech = createSech;
\No newline at end of file