UNPKG

1.47 kBJavaScriptView Raw
1'use strict'
2
3const deepMap = require('../../utils/collection/deepMap')
4
5function factory (type, config, load, typed) {
6 /**
7 * Calculate the hyperbolic sine of a value,
8 * defined as `sinh(x) = 1/2 * (exp(x) - exp(-x))`.
9 *
10 * For matrices, the function is evaluated element wise.
11 *
12 * Syntax:
13 *
14 * math.sinh(x)
15 *
16 * Examples:
17 *
18 * math.sinh(0.5) // returns number 0.5210953054937474
19 *
20 * See also:
21 *
22 * cosh, tanh
23 *
24 * @param {number | BigNumber | Complex | Unit | Array | Matrix} x Function input
25 * @return {number | BigNumber | Complex | Array | Matrix} Hyperbolic sine of x
26 */
27 const sinh = typed('sinh', {
28 'number': _sinh,
29
30 'Complex': function (x) {
31 return x.sinh()
32 },
33
34 'BigNumber': function (x) {
35 return x.sinh()
36 },
37
38 'Unit': function (x) {
39 if (!x.hasBase(type.Unit.BASE_UNITS.ANGLE)) {
40 throw new TypeError('Unit in function sinh is no angle')
41 }
42 return sinh(x.value)
43 },
44
45 'Array | Matrix': function (x) {
46 // deep map collection, skip zeros since sinh(0) = 0
47 return deepMap(x, sinh, true)
48 }
49 })
50
51 sinh.toTex = { 1: `\\sinh\\left(\${args[0]}\\right)` }
52
53 return sinh
54}
55
56/**
57 * Calculate the hyperbolic sine of a number
58 * @param {number} x
59 * @returns {number}
60 * @private
61 */
62const _sinh = Math.sinh || function (x) {
63 return (Math.exp(x) - Math.exp(-x)) / 2
64}
65
66exports.name = 'sinh'
67exports.factory = factory