asec.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { factory } from '../../utils/factory.js';
  2. import { asecNumber } from '../../plain/number/index.js';
  3. var name = 'asec';
  4. var dependencies = ['typed', 'config', 'Complex', 'BigNumber'];
  5. export var createAsec = /* #__PURE__ */factory(name, dependencies, _ref => {
  6. var {
  7. typed,
  8. config,
  9. Complex,
  10. BigNumber: _BigNumber
  11. } = _ref;
  12. /**
  13. * Calculate the inverse secant of a value. Defined as `asec(x) = acos(1/x)`.
  14. *
  15. * To avoid confusion with the matrix arcsecant, this function does not
  16. * apply to matrices.
  17. *
  18. * Syntax:
  19. *
  20. * math.asec(x)
  21. *
  22. * Examples:
  23. *
  24. * math.asec(2) // returns 1.0471975511965979
  25. * math.asec(math.sec(1.5)) // returns 1.5
  26. *
  27. * math.asec(0.5) // returns Complex 0 + 1.3169578969248166i
  28. *
  29. * See also:
  30. *
  31. * acos, acot, acsc
  32. *
  33. * @param {number | BigNumber | Complex} x Function input
  34. * @return {number | BigNumber | Complex} The arc secant of x
  35. */
  36. return typed(name, {
  37. number: function number(x) {
  38. if (x <= -1 || x >= 1 || config.predictable) {
  39. return asecNumber(x);
  40. }
  41. return new Complex(x, 0).asec();
  42. },
  43. Complex: function Complex(x) {
  44. return x.asec();
  45. },
  46. BigNumber: function BigNumber(x) {
  47. return new _BigNumber(1).div(x).acos();
  48. }
  49. });
  50. });