smallerEq.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.createSmallerEqNumber = exports.createSmallerEq = 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 = 'smallerEq';
  15. var dependencies = ['typed', 'config', 'matrix', 'DenseMatrix', 'concat'];
  16. var createSmallerEq = /* #__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 smaller or equal to y.
  43. *
  44. * The function returns true when x is smaller than y or the relative
  45. * difference between x and y is smaller 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.smallerEq(x, y)
  54. *
  55. * Examples:
  56. *
  57. * math.smaller(1 + 2, 3) // returns false
  58. * math.smallerEq(1 + 2, 3) // returns true
  59. *
  60. * See also:
  61. *
  62. * equal, unequal, smaller, larger, largerEq, compare
  63. *
  64. * @param {number | BigNumber | Fraction | boolean | Unit | string | Array | Matrix} x First value to compare
  65. * @param {number | BigNumber | Fraction | boolean | Unit | string | Array | Matrix} y Second value to compare
  66. * @return {boolean | Array | Matrix} Returns true when the x is smaller than y, else returns false
  67. */
  68. return typed(name, createSmallerEqNumber({
  69. typed: typed,
  70. config: config
  71. }), {
  72. 'boolean, boolean': function booleanBoolean(x, y) {
  73. return x <= y;
  74. },
  75. 'BigNumber, BigNumber': function BigNumberBigNumber(x, y) {
  76. return x.lte(y) || (0, _nearlyEqual.nearlyEqual)(x, y, config.epsilon);
  77. },
  78. 'Fraction, Fraction': function FractionFraction(x, y) {
  79. return x.compare(y) !== 1;
  80. },
  81. 'Complex, Complex': function ComplexComplex() {
  82. throw new TypeError('No ordering relation is defined for complex numbers');
  83. }
  84. }, compareUnits, matrixAlgorithmSuite({
  85. SS: matAlgo07xSSf,
  86. DS: matAlgo03xDSf,
  87. Ss: matAlgo12xSfs
  88. }));
  89. });
  90. exports.createSmallerEq = createSmallerEq;
  91. var createSmallerEqNumber = /* #__PURE__ */(0, _factory.factory)(name, ['typed', 'config'], function (_ref2) {
  92. var typed = _ref2.typed,
  93. config = _ref2.config;
  94. return typed(name, {
  95. 'number, number': function numberNumber(x, y) {
  96. return x <= y || (0, _number.nearlyEqual)(x, y, config.epsilon);
  97. }
  98. });
  99. });
  100. exports.createSmallerEqNumber = createSmallerEqNumber;