UNPKG

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