square.js 1.6 KB

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