UNPKG

5.05 kBJavaScriptView Raw
1import { nearlyEqual as bigNearlyEqual } from '../../utils/bignumber/nearlyEqual';
2import { nearlyEqual } from '../../utils/number';
3import { factory } from '../../utils/factory';
4import { createAlgorithm03 } from '../../type/matrix/utils/algorithm03';
5import { createAlgorithm07 } from '../../type/matrix/utils/algorithm07';
6import { createAlgorithm12 } from '../../type/matrix/utils/algorithm12';
7import { createAlgorithm14 } from '../../type/matrix/utils/algorithm14';
8import { createAlgorithm13 } from '../../type/matrix/utils/algorithm13';
9var name = 'largerEq';
10var dependencies = ['typed', 'config', 'matrix', 'DenseMatrix'];
11export var createLargerEq =
12/* #__PURE__ */
13factory(name, dependencies, function (_ref) {
14 var typed = _ref.typed,
15 config = _ref.config,
16 matrix = _ref.matrix,
17 DenseMatrix = _ref.DenseMatrix;
18 var algorithm03 = createAlgorithm03({
19 typed: typed
20 });
21 var algorithm07 = createAlgorithm07({
22 typed: typed,
23 DenseMatrix: DenseMatrix
24 });
25 var algorithm12 = createAlgorithm12({
26 typed: typed,
27 DenseMatrix: DenseMatrix
28 });
29 var algorithm13 = createAlgorithm13({
30 typed: typed
31 });
32 var algorithm14 = createAlgorithm14({
33 typed: typed
34 });
35 /**
36 * Test whether value x is larger or equal to y.
37 *
38 * The function returns true when x is larger than y or 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.largerEq(x, y)
48 *
49 * Examples:
50 *
51 * math.larger(2, 1 + 1) // returns false
52 * math.largerEq(2, 1 + 1) // returns true
53 *
54 * See also:
55 *
56 * equal, unequal, smaller, smallerEq, larger, compare
57 *
58 * @param {number | BigNumber | Fraction | boolean | Unit | string | Array | Matrix} x First value to compare
59 * @param {number | BigNumber | Fraction | boolean | Unit | string | Array | Matrix} y Second value to compare
60 * @return {boolean | Array | Matrix} Returns true when the x is larger or equal to y, else returns false
61 */
62
63 var largerEq = typed(name, {
64 'boolean, boolean': function booleanBoolean(x, y) {
65 return x >= y;
66 },
67 'number, number': function numberNumber(x, y) {
68 return x >= y || nearlyEqual(x, y, config.epsilon);
69 },
70 'BigNumber, BigNumber': function BigNumberBigNumber(x, y) {
71 return x.gte(y) || bigNearlyEqual(x, y, config.epsilon);
72 },
73 'Fraction, Fraction': function FractionFraction(x, y) {
74 return x.compare(y) !== -1;
75 },
76 'Complex, Complex': function ComplexComplex() {
77 throw new TypeError('No ordering relation is defined for complex numbers');
78 },
79 'Unit, Unit': function UnitUnit(x, y) {
80 if (!x.equalBase(y)) {
81 throw new Error('Cannot compare units with different base');
82 }
83
84 return largerEq(x.value, y.value);
85 },
86 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
87 return algorithm07(x, y, largerEq);
88 },
89 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
90 return algorithm03(y, x, largerEq, true);
91 },
92 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
93 return algorithm03(x, y, largerEq, false);
94 },
95 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
96 return algorithm13(x, y, largerEq);
97 },
98 'Array, Array': function ArrayArray(x, y) {
99 // use matrix implementation
100 return largerEq(matrix(x), matrix(y)).valueOf();
101 },
102 'Array, Matrix': function ArrayMatrix(x, y) {
103 // use matrix implementation
104 return largerEq(matrix(x), y);
105 },
106 'Matrix, Array': function MatrixArray(x, y) {
107 // use matrix implementation
108 return largerEq(x, matrix(y));
109 },
110 'SparseMatrix, any': function SparseMatrixAny(x, y) {
111 return algorithm12(x, y, largerEq, false);
112 },
113 'DenseMatrix, any': function DenseMatrixAny(x, y) {
114 return algorithm14(x, y, largerEq, false);
115 },
116 'any, SparseMatrix': function anySparseMatrix(x, y) {
117 return algorithm12(y, x, largerEq, true);
118 },
119 'any, DenseMatrix': function anyDenseMatrix(x, y) {
120 return algorithm14(y, x, largerEq, true);
121 },
122 'Array, any': function ArrayAny(x, y) {
123 // use matrix implementation
124 return algorithm14(matrix(x), y, largerEq, false).valueOf();
125 },
126 'any, Array': function anyArray(x, y) {
127 // use matrix implementation
128 return algorithm14(matrix(y), x, largerEq, true).valueOf();
129 }
130 });
131 return largerEq;
132});
133export var createLargerEqNumber =
134/* #__PURE__ */
135factory(name, ['typed', 'config'], function (_ref2) {
136 var typed = _ref2.typed,
137 config = _ref2.config;
138 return typed(name, {
139 'number, number': function numberNumber(x, y) {
140 return x >= y || nearlyEqual(x, y, config.epsilon);
141 }
142 });
143});
\No newline at end of file