unequal.js 3.4 KB

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