expm1.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.createExpm1 = void 0;
  6. var _factory = require("../../utils/factory.js");
  7. var _index = require("../../plain/number/index.js");
  8. var name = 'expm1';
  9. var dependencies = ['typed', 'Complex'];
  10. var createExpm1 = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
  11. var typed = _ref.typed,
  12. _Complex = _ref.Complex;
  13. /**
  14. * Calculate the value of subtracting 1 from the exponential value.
  15. * This function is more accurate than `math.exp(x)-1` when `x` is near 0
  16. * To avoid ambiguity with the matrix exponential `expm`, this function
  17. * does not operate on matrices; if you wish to apply it elementwise, see
  18. * the examples.
  19. *
  20. * Syntax:
  21. *
  22. * math.expm1(x)
  23. *
  24. * Examples:
  25. *
  26. * math.expm1(2) // returns number 6.38905609893065
  27. * math.pow(math.e, 2) - 1 // returns number 6.3890560989306495
  28. * math.expm1(1e-8) // returns number 1.0000000050000001e-8
  29. * math.exp(1e-8) - 1 // returns number 9.9999999392253e-9
  30. * math.log(math.expm1(2) + 1) // returns number 2
  31. *
  32. * math.map([1, 2, 3], math.expm1)
  33. * // returns Array [
  34. * // 1.718281828459045,
  35. * // 6.3890560989306495,
  36. * // 19.085536923187668
  37. * // ]
  38. *
  39. * See also:
  40. *
  41. * exp, expm, log, pow
  42. *
  43. * @param {number | BigNumber | Complex} x A number or matrix to apply expm1
  44. * @return {number | BigNumber | Complex} Exponential of `x`, minus one
  45. */
  46. return typed(name, {
  47. number: _index.expm1Number,
  48. Complex: function Complex(x) {
  49. var r = Math.exp(x.re);
  50. return new _Complex(r * Math.cos(x.im) - 1, r * Math.sin(x.im));
  51. },
  52. BigNumber: function BigNumber(x) {
  53. return x.exp().minus(1);
  54. }
  55. });
  56. });
  57. exports.createExpm1 = createExpm1;