equal.js 3.8 KB

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