asech.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { factory } from '../../utils/factory.js';
  2. import { asechNumber } from '../../plain/number/index.js';
  3. var name = 'asech';
  4. var dependencies = ['typed', 'config', 'Complex', 'BigNumber'];
  5. export var createAsech = /* #__PURE__ */factory(name, dependencies, _ref => {
  6. var {
  7. typed,
  8. config,
  9. Complex,
  10. BigNumber: _BigNumber
  11. } = _ref;
  12. /**
  13. * Calculate the hyperbolic arcsecant of a value,
  14. * defined as `asech(x) = acosh(1/x) = ln(sqrt(1/x^2 - 1) + 1/x)`.
  15. *
  16. * To avoid confusion with the matrix hyperbolic arcsecant, this function
  17. * does not apply to matrices.
  18. *
  19. * Syntax:
  20. *
  21. * math.asech(x)
  22. *
  23. * Examples:
  24. *
  25. * math.asech(0.5) // returns 1.3169578969248166
  26. *
  27. * See also:
  28. *
  29. * acsch, acoth
  30. *
  31. * @param {number | BigNumber | Complex} x Function input
  32. * @return {number | BigNumber | Complex} Hyperbolic arcsecant of x
  33. */
  34. return typed(name, {
  35. number: function number(x) {
  36. if (x <= 1 && x >= -1 || config.predictable) {
  37. var xInv = 1 / x;
  38. if (xInv > 0 || config.predictable) {
  39. return asechNumber(x);
  40. }
  41. var ret = Math.sqrt(xInv * xInv - 1);
  42. return new Complex(Math.log(ret - xInv), Math.PI);
  43. }
  44. return new Complex(x, 0).asech();
  45. },
  46. Complex: function Complex(x) {
  47. return x.asech();
  48. },
  49. BigNumber: function BigNumber(x) {
  50. return new _BigNumber(1).div(x).acosh();
  51. }
  52. });
  53. });