smaller.js 3.7 KB

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