1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.createCompareNumber = exports.createCompare = void 0;
|
7 |
|
8 | var _nearlyEqual = require("../../utils/bignumber/nearlyEqual");
|
9 |
|
10 | var _number = require("../../utils/number");
|
11 |
|
12 | var _factory = require("../../utils/factory");
|
13 |
|
14 | var _algorithm = require("../../type/matrix/utils/algorithm03");
|
15 |
|
16 | var _algorithm2 = require("../../type/matrix/utils/algorithm12");
|
17 |
|
18 | var _algorithm3 = require("../../type/matrix/utils/algorithm14");
|
19 |
|
20 | var _algorithm4 = require("../../type/matrix/utils/algorithm13");
|
21 |
|
22 | var _algorithm5 = require("../../type/matrix/utils/algorithm05");
|
23 |
|
24 | var name = 'compare';
|
25 | var dependencies = ['typed', 'config', 'matrix', 'equalScalar', 'BigNumber', 'Fraction', 'DenseMatrix'];
|
26 | var createCompare = (0, _factory.factory)(name, dependencies, function (_ref) {
|
27 | var typed = _ref.typed,
|
28 | config = _ref.config,
|
29 | equalScalar = _ref.equalScalar,
|
30 | matrix = _ref.matrix,
|
31 | BigNumber = _ref.BigNumber,
|
32 | Fraction = _ref.Fraction,
|
33 | DenseMatrix = _ref.DenseMatrix;
|
34 | var algorithm03 = (0, _algorithm.createAlgorithm03)({
|
35 | typed: typed
|
36 | });
|
37 | var algorithm05 = (0, _algorithm5.createAlgorithm05)({
|
38 | typed: typed,
|
39 | equalScalar: equalScalar
|
40 | });
|
41 | var algorithm12 = (0, _algorithm2.createAlgorithm12)({
|
42 | typed: typed,
|
43 | DenseMatrix: DenseMatrix
|
44 | });
|
45 | var algorithm13 = (0, _algorithm4.createAlgorithm13)({
|
46 | typed: typed
|
47 | });
|
48 | var algorithm14 = (0, _algorithm3.createAlgorithm14)({
|
49 | typed: typed
|
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 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 | var compare = typed(name, {
|
90 | 'boolean, boolean': function booleanBoolean(x, y) {
|
91 | return x === y ? 0 : x > y ? 1 : -1;
|
92 | },
|
93 | 'number, number': function numberNumber(x, y) {
|
94 | return (0, _number.nearlyEqual)(x, y, config.epsilon) ? 0 : x > y ? 1 : -1;
|
95 | },
|
96 | 'BigNumber, BigNumber': function BigNumberBigNumber(x, y) {
|
97 | return (0, _nearlyEqual.nearlyEqual)(x, y, config.epsilon) ? new BigNumber(0) : new BigNumber(x.cmp(y));
|
98 | },
|
99 | 'Fraction, Fraction': function FractionFraction(x, y) {
|
100 | return new Fraction(x.compare(y));
|
101 | },
|
102 | 'Complex, Complex': function ComplexComplex() {
|
103 | throw new TypeError('No ordering relation is defined for complex numbers');
|
104 | },
|
105 | 'Unit, Unit': function UnitUnit(x, y) {
|
106 | if (!x.equalBase(y)) {
|
107 | throw new Error('Cannot compare units with different base');
|
108 | }
|
109 |
|
110 | return compare(x.value, y.value);
|
111 | },
|
112 | 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
|
113 | return algorithm05(x, y, compare);
|
114 | },
|
115 | 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
|
116 | return algorithm03(y, x, compare, true);
|
117 | },
|
118 | 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
|
119 | return algorithm03(x, y, compare, false);
|
120 | },
|
121 | 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
|
122 | return algorithm13(x, y, compare);
|
123 | },
|
124 | 'Array, Array': function ArrayArray(x, y) {
|
125 |
|
126 | return compare(matrix(x), matrix(y)).valueOf();
|
127 | },
|
128 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
129 |
|
130 | return compare(matrix(x), y);
|
131 | },
|
132 | 'Matrix, Array': function MatrixArray(x, y) {
|
133 |
|
134 | return compare(x, matrix(y));
|
135 | },
|
136 | 'SparseMatrix, any': function SparseMatrixAny(x, y) {
|
137 | return algorithm12(x, y, compare, false);
|
138 | },
|
139 | 'DenseMatrix, any': function DenseMatrixAny(x, y) {
|
140 | return algorithm14(x, y, compare, false);
|
141 | },
|
142 | 'any, SparseMatrix': function anySparseMatrix(x, y) {
|
143 | return algorithm12(y, x, compare, true);
|
144 | },
|
145 | 'any, DenseMatrix': function anyDenseMatrix(x, y) {
|
146 | return algorithm14(y, x, compare, true);
|
147 | },
|
148 | 'Array, any': function ArrayAny(x, y) {
|
149 |
|
150 | return algorithm14(matrix(x), y, compare, false).valueOf();
|
151 | },
|
152 | 'any, Array': function anyArray(x, y) {
|
153 |
|
154 | return algorithm14(matrix(y), x, compare, true).valueOf();
|
155 | }
|
156 | });
|
157 | return compare;
|
158 | });
|
159 | exports.createCompare = createCompare;
|
160 | var createCompareNumber = (0, _factory.factory)(name, ['typed', 'config'], function (_ref2) {
|
161 | var typed = _ref2.typed,
|
162 | config = _ref2.config;
|
163 | return typed(name, {
|
164 | 'number, number': function numberNumber(x, y) {
|
165 | return (0, _number.nearlyEqual)(x, y, config.epsilon) ? 0 : x > y ? 1 : -1;
|
166 | }
|
167 | });
|
168 | });
|
169 | exports.createCompareNumber = createCompareNumber; |
\ | No newline at end of file |