unequal.js 3.4 KB

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