larger.js 3.7 KB

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