UNPKG

5.39 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.createSmallerEqNumber = exports.createSmallerEq = 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 = 'smallerEq';
25var dependencies = ['typed', 'config', 'matrix', 'DenseMatrix'];
26var createSmallerEq = /* #__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 or equal to y.
50 *
51 * The function returns true when x is smaller than y or 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.smallerEq(x, y)
61 *
62 * Examples:
63 *
64 * math.smaller(1 + 2, 3) // returns false
65 * math.smallerEq(1 + 2, 3) // returns true
66 *
67 * See also:
68 *
69 * equal, unequal, smaller, larger, largerEq, compare
70 *
71 * @param {number | BigNumber | Fraction | boolean | Unit | string | Array | Matrix} x First value to compare
72 * @param {number | BigNumber | Fraction | boolean | Unit | string | Array | Matrix} y Second value to compare
73 * @return {boolean | Array | Matrix} Returns true when the x is smaller than y, else returns false
74 */
75
76 var smallerEq = typed(name, {
77 'boolean, boolean': function booleanBoolean(x, y) {
78 return x <= y;
79 },
80 'number, number': function numberNumber(x, y) {
81 return x <= y || (0, _number.nearlyEqual)(x, y, config.epsilon);
82 },
83 'BigNumber, BigNumber': function BigNumberBigNumber(x, y) {
84 return x.lte(y) || (0, _nearlyEqual.nearlyEqual)(x, y, config.epsilon);
85 },
86 'Fraction, Fraction': function FractionFraction(x, y) {
87 return x.compare(y) !== 1;
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 smallerEq(x.value, y.value);
98 },
99 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
100 return algorithm07(x, y, smallerEq);
101 },
102 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
103 return algorithm03(y, x, smallerEq, true);
104 },
105 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
106 return algorithm03(x, y, smallerEq, false);
107 },
108 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
109 return algorithm13(x, y, smallerEq);
110 },
111 'Array, Array': function ArrayArray(x, y) {
112 // use matrix implementation
113 return smallerEq(matrix(x), matrix(y)).valueOf();
114 },
115 'Array, Matrix': function ArrayMatrix(x, y) {
116 // use matrix implementation
117 return smallerEq(matrix(x), y);
118 },
119 'Matrix, Array': function MatrixArray(x, y) {
120 // use matrix implementation
121 return smallerEq(x, matrix(y));
122 },
123 'SparseMatrix, any': function SparseMatrixAny(x, y) {
124 return algorithm12(x, y, smallerEq, false);
125 },
126 'DenseMatrix, any': function DenseMatrixAny(x, y) {
127 return algorithm14(x, y, smallerEq, false);
128 },
129 'any, SparseMatrix': function anySparseMatrix(x, y) {
130 return algorithm12(y, x, smallerEq, true);
131 },
132 'any, DenseMatrix': function anyDenseMatrix(x, y) {
133 return algorithm14(y, x, smallerEq, true);
134 },
135 'Array, any': function ArrayAny(x, y) {
136 // use matrix implementation
137 return algorithm14(matrix(x), y, smallerEq, false).valueOf();
138 },
139 'any, Array': function anyArray(x, y) {
140 // use matrix implementation
141 return algorithm14(matrix(y), x, smallerEq, true).valueOf();
142 }
143 });
144 return smallerEq;
145});
146exports.createSmallerEq = createSmallerEq;
147var createSmallerEqNumber = /* #__PURE__ */(0, _factory.factory)(name, ['typed', 'config'], function (_ref2) {
148 var typed = _ref2.typed,
149 config = _ref2.config;
150 return typed(name, {
151 'number, number': function numberNumber(x, y) {
152 return x <= y || (0, _number.nearlyEqual)(x, y, config.epsilon);
153 }
154 });
155});
156exports.createSmallerEqNumber = createSmallerEqNumber;
\No newline at end of file