smallerEq.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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'];
  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. var matAlgo03xDSf = (0, _matAlgo03xDSf.createMatAlgo03xDSf)({
  22. typed: typed
  23. });
  24. var matAlgo07xSSf = (0, _matAlgo07xSSf.createMatAlgo07xSSf)({
  25. typed: typed,
  26. DenseMatrix: DenseMatrix
  27. });
  28. var matAlgo12xSfs = (0, _matAlgo12xSfs.createMatAlgo12xSfs)({
  29. typed: typed,
  30. DenseMatrix: DenseMatrix
  31. });
  32. var matrixAlgorithmSuite = (0, _matrixAlgorithmSuite.createMatrixAlgorithmSuite)({
  33. typed: typed,
  34. matrix: matrix
  35. });
  36. var compareUnits = (0, _compareUnits.createCompareUnits)({
  37. typed: typed
  38. });
  39. /**
  40. * Test whether value x is smaller or equal to y.
  41. *
  42. * The function returns true when x is smaller than y or the relative
  43. * difference between x and y is smaller than the configured epsilon. The
  44. * function cannot be used to compare values smaller than approximately 2.22e-16.
  45. *
  46. * For matrices, the function is evaluated element wise.
  47. * Strings are compared by their numerical value.
  48. *
  49. * Syntax:
  50. *
  51. * math.smallerEq(x, y)
  52. *
  53. * Examples:
  54. *
  55. * math.smaller(1 + 2, 3) // returns false
  56. * math.smallerEq(1 + 2, 3) // returns true
  57. *
  58. * See also:
  59. *
  60. * equal, unequal, smaller, larger, largerEq, compare
  61. *
  62. * @param {number | BigNumber | Fraction | boolean | Unit | string | Array | Matrix} x First value to compare
  63. * @param {number | BigNumber | Fraction | boolean | Unit | string | Array | Matrix} y Second value to compare
  64. * @return {boolean | Array | Matrix} Returns true when the x is smaller than y, else returns false
  65. */
  66. return typed(name, createSmallerEqNumber({
  67. typed: typed,
  68. config: config
  69. }), {
  70. 'boolean, boolean': function booleanBoolean(x, y) {
  71. return x <= y;
  72. },
  73. 'BigNumber, BigNumber': function BigNumberBigNumber(x, y) {
  74. return x.lte(y) || (0, _nearlyEqual.nearlyEqual)(x, y, config.epsilon);
  75. },
  76. 'Fraction, Fraction': function FractionFraction(x, y) {
  77. return x.compare(y) !== 1;
  78. },
  79. 'Complex, Complex': function ComplexComplex() {
  80. throw new TypeError('No ordering relation is defined for complex numbers');
  81. }
  82. }, compareUnits, matrixAlgorithmSuite({
  83. SS: matAlgo07xSSf,
  84. DS: matAlgo03xDSf,
  85. Ss: matAlgo12xSfs
  86. }));
  87. });
  88. exports.createSmallerEq = createSmallerEq;
  89. var createSmallerEqNumber = /* #__PURE__ */(0, _factory.factory)(name, ['typed', 'config'], function (_ref2) {
  90. var typed = _ref2.typed,
  91. config = _ref2.config;
  92. return typed(name, {
  93. 'number, number': function numberNumber(x, y) {
  94. return x <= y || (0, _number.nearlyEqual)(x, y, config.epsilon);
  95. }
  96. });
  97. });
  98. exports.createSmallerEqNumber = createSmallerEqNumber;