UNPKG

5.48 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.createSmallerNumber = exports.createSmaller = void 0;
7
8var _nearlyEqual = require("../../utils/bignumber/nearlyEqual");
9
10var _number = require("../../utils/number");
11
12var _factory = require("../../utils/factory");
13
14var _algorithm = require("../../type/matrix/utils/algorithm03");
15
16var _algorithm2 = require("../../type/matrix/utils/algorithm07");
17
18var _algorithm3 = require("../../type/matrix/utils/algorithm12");
19
20var _algorithm4 = require("../../type/matrix/utils/algorithm14");
21
22var _algorithm5 = require("../../type/matrix/utils/algorithm13");
23
24var name = 'smaller';
25var dependencies = ['typed', 'config', 'matrix', 'DenseMatrix'];
26var createSmaller = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
27 var typed = _ref.typed,
28 config = _ref.config,
29 matrix = _ref.matrix,
30 DenseMatrix = _ref.DenseMatrix;
31 var algorithm03 = (0, _algorithm.createAlgorithm03)({
32 typed: typed
33 });
34 var algorithm07 = (0, _algorithm2.createAlgorithm07)({
35 typed: typed,
36 DenseMatrix: DenseMatrix
37 });
38 var algorithm12 = (0, _algorithm3.createAlgorithm12)({
39 typed: typed,
40 DenseMatrix: DenseMatrix
41 });
42 var algorithm13 = (0, _algorithm5.createAlgorithm13)({
43 typed: typed
44 });
45 var algorithm14 = (0, _algorithm4.createAlgorithm14)({
46 typed: typed
47 });
48 /**
49 * Test whether value x is smaller than y.
50 *
51 * The function returns true when x is smaller than y and the relative
52 * difference between x and y is smaller than the configured epsilon. The
53 * function cannot be used to compare values smaller than approximately 2.22e-16.
54 *
55 * For matrices, the function is evaluated element wise.
56 * Strings are compared by their numerical value.
57 *
58 * Syntax:
59 *
60 * math.smaller(x, y)
61 *
62 * Examples:
63 *
64 * math.smaller(2, 3) // returns true
65 * math.smaller(5, 2 * 2) // returns false
66 *
67 * const a = math.unit('5 cm')
68 * const b = math.unit('2 inch')
69 * math.smaller(a, b) // returns true
70 *
71 * See also:
72 *
73 * equal, unequal, smallerEq, smaller, smallerEq, compare
74 *
75 * @param {number | BigNumber | Fraction | boolean | Unit | string | Array | Matrix} x First value to compare
76 * @param {number | BigNumber | Fraction | boolean | Unit | string | Array | Matrix} y Second value to compare
77 * @return {boolean | Array | Matrix} Returns true when the x is smaller than y, else returns false
78 */
79
80 var smaller = typed(name, {
81 'boolean, boolean': function booleanBoolean(x, y) {
82 return x < y;
83 },
84 'number, number': function numberNumber(x, y) {
85 return x < y && !(0, _number.nearlyEqual)(x, y, config.epsilon);
86 },
87 'BigNumber, BigNumber': function BigNumberBigNumber(x, y) {
88 return x.lt(y) && !(0, _nearlyEqual.nearlyEqual)(x, y, config.epsilon);
89 },
90 'Fraction, Fraction': function FractionFraction(x, y) {
91 return x.compare(y) === -1;
92 },
93 'Complex, Complex': function ComplexComplex(x, y) {
94 throw new TypeError('No ordering relation is defined for complex numbers');
95 },
96 'Unit, Unit': function UnitUnit(x, y) {
97 if (!x.equalBase(y)) {
98 throw new Error('Cannot compare units with different base');
99 }
100
101 return smaller(x.value, y.value);
102 },
103 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
104 return algorithm07(x, y, smaller);
105 },
106 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
107 return algorithm03(y, x, smaller, true);
108 },
109 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
110 return algorithm03(x, y, smaller, false);
111 },
112 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
113 return algorithm13(x, y, smaller);
114 },
115 'Array, Array': function ArrayArray(x, y) {
116 // use matrix implementation
117 return smaller(matrix(x), matrix(y)).valueOf();
118 },
119 'Array, Matrix': function ArrayMatrix(x, y) {
120 // use matrix implementation
121 return smaller(matrix(x), y);
122 },
123 'Matrix, Array': function MatrixArray(x, y) {
124 // use matrix implementation
125 return smaller(x, matrix(y));
126 },
127 'SparseMatrix, any': function SparseMatrixAny(x, y) {
128 return algorithm12(x, y, smaller, false);
129 },
130 'DenseMatrix, any': function DenseMatrixAny(x, y) {
131 return algorithm14(x, y, smaller, false);
132 },
133 'any, SparseMatrix': function anySparseMatrix(x, y) {
134 return algorithm12(y, x, smaller, true);
135 },
136 'any, DenseMatrix': function anyDenseMatrix(x, y) {
137 return algorithm14(y, x, smaller, true);
138 },
139 'Array, any': function ArrayAny(x, y) {
140 // use matrix implementation
141 return algorithm14(matrix(x), y, smaller, false).valueOf();
142 },
143 'any, Array': function anyArray(x, y) {
144 // use matrix implementation
145 return algorithm14(matrix(y), x, smaller, true).valueOf();
146 }
147 });
148 return smaller;
149});
150exports.createSmaller = createSmaller;
151var createSmallerNumber = /* #__PURE__ */(0, _factory.factory)(name, ['typed', 'config'], function (_ref2) {
152 var typed = _ref2.typed,
153 config = _ref2.config;
154 return typed(name, {
155 'number, number': function numberNumber(x, y) {
156 return x < y && !(0, _number.nearlyEqual)(x, y, config.epsilon);
157 }
158 });
159});
160exports.createSmallerNumber = createSmallerNumber;
\No newline at end of file