equal.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.createEqualNumber = exports.createEqual = void 0;
  6. var _factory = require("../../utils/factory.js");
  7. var _matAlgo03xDSf = require("../../type/matrix/utils/matAlgo03xDSf.js");
  8. var _matAlgo07xSSf = require("../../type/matrix/utils/matAlgo07xSSf.js");
  9. var _matAlgo12xSfs = require("../../type/matrix/utils/matAlgo12xSfs.js");
  10. var _matrixAlgorithmSuite = require("../../type/matrix/utils/matrixAlgorithmSuite.js");
  11. var name = 'equal';
  12. var dependencies = ['typed', 'matrix', 'equalScalar', 'DenseMatrix'];
  13. var createEqual = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
  14. var typed = _ref.typed,
  15. matrix = _ref.matrix,
  16. equalScalar = _ref.equalScalar,
  17. DenseMatrix = _ref.DenseMatrix;
  18. var matAlgo03xDSf = (0, _matAlgo03xDSf.createMatAlgo03xDSf)({
  19. typed: typed
  20. });
  21. var matAlgo07xSSf = (0, _matAlgo07xSSf.createMatAlgo07xSSf)({
  22. typed: typed,
  23. DenseMatrix: DenseMatrix
  24. });
  25. var matAlgo12xSfs = (0, _matAlgo12xSfs.createMatAlgo12xSfs)({
  26. typed: typed,
  27. DenseMatrix: DenseMatrix
  28. });
  29. var matrixAlgorithmSuite = (0, _matrixAlgorithmSuite.createMatrixAlgorithmSuite)({
  30. typed: typed,
  31. matrix: matrix
  32. });
  33. /**
  34. * Test whether two values are equal.
  35. *
  36. * The function tests whether the relative difference between x and y is
  37. * smaller than the configured epsilon. The function cannot be used to
  38. * compare values smaller than approximately 2.22e-16.
  39. *
  40. * For matrices, the function is evaluated element wise.
  41. * In case of complex numbers, x.re must equal y.re, and x.im must equal y.im.
  42. *
  43. * Values `null` and `undefined` are compared strictly, thus `null` is only
  44. * equal to `null` and nothing else, and `undefined` is only equal to
  45. * `undefined` and nothing else. Strings are compared by their numerical value.
  46. *
  47. * Syntax:
  48. *
  49. * math.equal(x, y)
  50. *
  51. * Examples:
  52. *
  53. * math.equal(2 + 2, 3) // returns false
  54. * math.equal(2 + 2, 4) // returns true
  55. *
  56. * const a = math.unit('50 cm')
  57. * const b = math.unit('5 m')
  58. * math.equal(a, b) // returns true
  59. *
  60. * const c = [2, 5, 1]
  61. * const d = [2, 7, 1]
  62. *
  63. * math.equal(c, d) // returns [true, false, true]
  64. * math.deepEqual(c, d) // returns false
  65. *
  66. * math.equal("1000", "1e3") // returns true
  67. * math.equal(0, null) // returns false
  68. *
  69. * See also:
  70. *
  71. * unequal, smaller, smallerEq, larger, largerEq, compare, deepEqual, equalText
  72. *
  73. * @param {number | BigNumber | boolean | Complex | Unit | string | Array | Matrix} x First value to compare
  74. * @param {number | BigNumber | boolean | Complex | Unit | string | Array | Matrix} y Second value to compare
  75. * @return {boolean | Array | Matrix} Returns true when the compared values are equal, else returns false
  76. */
  77. return typed(name, createEqualNumber({
  78. typed: typed,
  79. equalScalar: equalScalar
  80. }), matrixAlgorithmSuite({
  81. elop: equalScalar,
  82. SS: matAlgo07xSSf,
  83. DS: matAlgo03xDSf,
  84. Ss: matAlgo12xSfs
  85. }));
  86. });
  87. exports.createEqual = createEqual;
  88. var createEqualNumber = (0, _factory.factory)(name, ['typed', 'equalScalar'], function (_ref2) {
  89. var typed = _ref2.typed,
  90. equalScalar = _ref2.equalScalar;
  91. return typed(name, {
  92. 'any, any': function anyAny(x, y) {
  93. // strict equality for null and undefined?
  94. if (x === null) {
  95. return y === null;
  96. }
  97. if (y === null) {
  98. return x === null;
  99. }
  100. if (x === undefined) {
  101. return y === undefined;
  102. }
  103. if (y === undefined) {
  104. return x === undefined;
  105. }
  106. return equalScalar(x, y);
  107. }
  108. });
  109. });
  110. exports.createEqualNumber = createEqualNumber;