cube.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { factory } from '../../utils/factory.js';
  2. import { cubeNumber } from '../../plain/number/index.js';
  3. var name = 'cube';
  4. var dependencies = ['typed'];
  5. export var createCube = /* #__PURE__ */factory(name, dependencies, _ref => {
  6. var {
  7. typed
  8. } = _ref;
  9. /**
  10. * Compute the cube of a value, `x * x * x`.
  11. * To avoid confusion with `pow(M,3)`, this function does not apply to matrices.
  12. * If you wish to cube every entry of a matrix, see the examples.
  13. *
  14. * Syntax:
  15. *
  16. * math.cube(x)
  17. *
  18. * Examples:
  19. *
  20. * math.cube(2) // returns number 8
  21. * math.pow(2, 3) // returns number 8
  22. * math.cube(4) // returns number 64
  23. * 4 * 4 * 4 // returns number 64
  24. *
  25. * math.map([1, 2, 3, 4], math.cube) // returns Array [1, 8, 27, 64]
  26. *
  27. * See also:
  28. *
  29. * multiply, square, pow, cbrt
  30. *
  31. * @param {number | BigNumber | Fraction | Complex | Unit} x Number for which to calculate the cube
  32. * @return {number | BigNumber | Fraction | Complex | Unit} Cube of x
  33. */
  34. return typed(name, {
  35. number: cubeNumber,
  36. Complex: function Complex(x) {
  37. return x.mul(x).mul(x); // Is faster than pow(x, 3)
  38. },
  39. BigNumber: function BigNumber(x) {
  40. return x.times(x).times(x);
  41. },
  42. Fraction: function Fraction(x) {
  43. return x.pow(3); // Is faster than mul()mul()mul()
  44. },
  45. Unit: function Unit(x) {
  46. return x.pow(3);
  47. }
  48. });
  49. });