UNPKG

mathjs

Version:

Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with dif

52 lines (46 loc) 1.29 kB
import { factory } from '../../utils/factory' import { deepMap } from '../../utils/collection' import { atanhNumber } from '../../plain/number' const name = 'atanh' const dependencies = ['typed', 'config', 'Complex'] export const createAtanh = /* #__PURE__ */ factory(name, dependencies, ({ typed, config, Complex }) => { /** * Calculate the hyperbolic arctangent of a value, * defined as `atanh(x) = ln((1 + x)/(1 - x)) / 2`. * * For matrices, the function is evaluated element wise. * * Syntax: * * math.atanh(x) * * Examples: * * math.atanh(0.5) // returns 0.5493061443340549 * * See also: * * acosh, asinh * * @param {number | Complex | Array | Matrix} x Function input * @return {number | Complex | Array | Matrix} Hyperbolic arctangent of x */ return typed(name, { number: function (x) { if ((x <= 1 && x >= -1) || config.predictable) { return atanhNumber(x) } return new Complex(x, 0).atanh() }, Complex: function (x) { return x.atanh() }, BigNumber: function (x) { return x.atanh() }, 'Array | Matrix': function (x) { // deep map collection, skip zeros since atanh(0) = 0 return deepMap(x, this, true) } }) })