cube.js 1.6 KB

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