larger.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import { nearlyEqual as bigNearlyEqual } from '../../utils/bignumber/nearlyEqual.js';
  2. import { nearlyEqual } from '../../utils/number.js';
  3. import { factory } from '../../utils/factory.js';
  4. import { createMatAlgo03xDSf } from '../../type/matrix/utils/matAlgo03xDSf.js';
  5. import { createMatAlgo07xSSf } from '../../type/matrix/utils/matAlgo07xSSf.js';
  6. import { createMatAlgo12xSfs } from '../../type/matrix/utils/matAlgo12xSfs.js';
  7. import { createMatrixAlgorithmSuite } from '../../type/matrix/utils/matrixAlgorithmSuite.js';
  8. import { createCompareUnits } from './compareUnits.js';
  9. var name = 'larger';
  10. var dependencies = ['typed', 'config', 'matrix', 'DenseMatrix'];
  11. export var createLarger = /* #__PURE__ */factory(name, dependencies, _ref => {
  12. var {
  13. typed,
  14. config,
  15. matrix,
  16. DenseMatrix
  17. } = _ref;
  18. var matAlgo03xDSf = createMatAlgo03xDSf({
  19. typed
  20. });
  21. var matAlgo07xSSf = createMatAlgo07xSSf({
  22. typed,
  23. DenseMatrix
  24. });
  25. var matAlgo12xSfs = createMatAlgo12xSfs({
  26. typed,
  27. DenseMatrix
  28. });
  29. var matrixAlgorithmSuite = createMatrixAlgorithmSuite({
  30. typed,
  31. matrix
  32. });
  33. var compareUnits = createCompareUnits({
  34. typed
  35. });
  36. /**
  37. * Test whether value x is larger than y.
  38. *
  39. * The function returns true when x is larger than y and the relative
  40. * difference between x and y is larger than the configured epsilon. The
  41. * function cannot be used to compare values smaller than approximately 2.22e-16.
  42. *
  43. * For matrices, the function is evaluated element wise.
  44. * Strings are compared by their numerical value.
  45. *
  46. * Syntax:
  47. *
  48. * math.larger(x, y)
  49. *
  50. * Examples:
  51. *
  52. * math.larger(2, 3) // returns false
  53. * math.larger(5, 2 + 2) // returns true
  54. *
  55. * const a = math.unit('5 cm')
  56. * const b = math.unit('2 inch')
  57. * math.larger(a, b) // returns false
  58. *
  59. * See also:
  60. *
  61. * equal, unequal, smaller, smallerEq, largerEq, compare
  62. *
  63. * @param {number | BigNumber | Fraction | boolean | Unit | string | Array | Matrix} x First value to compare
  64. * @param {number | BigNumber | Fraction | boolean | Unit | string | Array | Matrix} y Second value to compare
  65. * @return {boolean | Array | Matrix} Returns true when the x is larger than y, else returns false
  66. */
  67. return typed(name, createLargerNumber({
  68. typed,
  69. config
  70. }), {
  71. 'boolean, boolean': (x, y) => x > y,
  72. 'BigNumber, BigNumber': function BigNumberBigNumber(x, y) {
  73. return x.gt(y) && !bigNearlyEqual(x, y, config.epsilon);
  74. },
  75. 'Fraction, Fraction': (x, y) => x.compare(y) === 1,
  76. 'Complex, Complex': function ComplexComplex() {
  77. throw new TypeError('No ordering relation is defined for complex numbers');
  78. }
  79. }, compareUnits, matrixAlgorithmSuite({
  80. SS: matAlgo07xSSf,
  81. DS: matAlgo03xDSf,
  82. Ss: matAlgo12xSfs
  83. }));
  84. });
  85. export var createLargerNumber = /* #__PURE__ */factory(name, ['typed', 'config'], _ref2 => {
  86. var {
  87. typed,
  88. config
  89. } = _ref2;
  90. return typed(name, {
  91. 'number, number': function numberNumber(x, y) {
  92. return x > y && !nearlyEqual(x, y, config.epsilon);
  93. }
  94. });
  95. });