expm1.js 1.7 KB

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