unequal.js 3.9 KB

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