1 | import { nearlyEqual as bigNearlyEqual } from '../../utils/bignumber/nearlyEqual.js';
|
2 | import { nearlyEqual } from '../../utils/number.js';
|
3 | import { factory } from '../../utils/factory.js';
|
4 | import { createAlgorithm03 } from '../../type/matrix/utils/algorithm03.js';
|
5 | import { createAlgorithm12 } from '../../type/matrix/utils/algorithm12.js';
|
6 | import { createAlgorithm14 } from '../../type/matrix/utils/algorithm14.js';
|
7 | import { createAlgorithm13 } from '../../type/matrix/utils/algorithm13.js';
|
8 | import { createAlgorithm05 } from '../../type/matrix/utils/algorithm05.js';
|
9 | var name = 'compare';
|
10 | var dependencies = ['typed', 'config', 'matrix', 'equalScalar', 'BigNumber', 'Fraction', 'DenseMatrix'];
|
11 | export var createCompare = factory(name, dependencies, _ref => {
|
12 | var {
|
13 | typed,
|
14 | config,
|
15 | equalScalar,
|
16 | matrix,
|
17 | BigNumber,
|
18 | Fraction,
|
19 | DenseMatrix
|
20 | } = _ref;
|
21 | var algorithm03 = createAlgorithm03({
|
22 | typed
|
23 | });
|
24 | var algorithm05 = createAlgorithm05({
|
25 | typed,
|
26 | equalScalar
|
27 | });
|
28 | var algorithm12 = createAlgorithm12({
|
29 | typed,
|
30 | DenseMatrix
|
31 | });
|
32 | var algorithm13 = createAlgorithm13({
|
33 | typed
|
34 | });
|
35 | var algorithm14 = createAlgorithm14({
|
36 | typed
|
37 | });
|
38 | |
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 | return typed(name, {
|
77 | 'boolean, boolean': function booleanBoolean(x, y) {
|
78 | return x === y ? 0 : x > y ? 1 : -1;
|
79 | },
|
80 | 'number, number': function numberNumber(x, y) {
|
81 | return nearlyEqual(x, y, config.epsilon) ? 0 : x > y ? 1 : -1;
|
82 | },
|
83 | 'BigNumber, BigNumber': function BigNumberBigNumber(x, y) {
|
84 | return bigNearlyEqual(x, y, config.epsilon) ? new BigNumber(0) : new BigNumber(x.cmp(y));
|
85 | },
|
86 | 'Fraction, Fraction': function FractionFraction(x, y) {
|
87 | return new Fraction(x.compare(y));
|
88 | },
|
89 | 'Complex, Complex': function ComplexComplex() {
|
90 | throw new TypeError('No ordering relation is defined for complex numbers');
|
91 | },
|
92 | 'Unit, Unit': function UnitUnit(x, y) {
|
93 | if (!x.equalBase(y)) {
|
94 | throw new Error('Cannot compare units with different base');
|
95 | }
|
96 |
|
97 | return this(x.value, y.value);
|
98 | },
|
99 | 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
|
100 | return algorithm05(x, y, this);
|
101 | },
|
102 | 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
|
103 | return algorithm03(y, x, this, true);
|
104 | },
|
105 | 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
|
106 | return algorithm03(x, y, this, false);
|
107 | },
|
108 | 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
|
109 | return algorithm13(x, y, this);
|
110 | },
|
111 | 'Array, Array': function ArrayArray(x, y) {
|
112 |
|
113 | return this(matrix(x), matrix(y)).valueOf();
|
114 | },
|
115 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
116 |
|
117 | return this(matrix(x), y);
|
118 | },
|
119 | 'Matrix, Array': function MatrixArray(x, y) {
|
120 |
|
121 | return this(x, matrix(y));
|
122 | },
|
123 | 'SparseMatrix, any': function SparseMatrixAny(x, y) {
|
124 | return algorithm12(x, y, this, false);
|
125 | },
|
126 | 'DenseMatrix, any': function DenseMatrixAny(x, y) {
|
127 | return algorithm14(x, y, this, false);
|
128 | },
|
129 | 'any, SparseMatrix': function anySparseMatrix(x, y) {
|
130 | return algorithm12(y, x, this, true);
|
131 | },
|
132 | 'any, DenseMatrix': function anyDenseMatrix(x, y) {
|
133 | return algorithm14(y, x, this, true);
|
134 | },
|
135 | 'Array, any': function ArrayAny(x, y) {
|
136 |
|
137 | return algorithm14(matrix(x), y, this, false).valueOf();
|
138 | },
|
139 | 'any, Array': function anyArray(x, y) {
|
140 |
|
141 | return algorithm14(matrix(y), x, this, true).valueOf();
|
142 | }
|
143 | });
|
144 | });
|
145 | export var createCompareNumber = factory(name, ['typed', 'config'], _ref2 => {
|
146 | var {
|
147 | typed,
|
148 | config
|
149 | } = _ref2;
|
150 | return typed(name, {
|
151 | 'number, number': function numberNumber(x, y) {
|
152 | return nearlyEqual(x, y, config.epsilon) ? 0 : x > y ? 1 : -1;
|
153 | }
|
154 | });
|
155 | }); |
\ | No newline at end of file |