feat:node-modules

This commit is contained in:
houjunxiang
2025-11-24 10:26:18 +08:00
parent 753766893b
commit 8a3e48d856
8825 changed files with 567399 additions and 1 deletions

View File

@@ -0,0 +1,120 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createCompareNumber = exports.createCompare = void 0;
var _nearlyEqual = require("../../utils/bignumber/nearlyEqual.js");
var _number = require("../../utils/number.js");
var _factory = require("../../utils/factory.js");
var _matAlgo03xDSf = require("../../type/matrix/utils/matAlgo03xDSf.js");
var _matAlgo12xSfs = require("../../type/matrix/utils/matAlgo12xSfs.js");
var _matAlgo05xSfSf = require("../../type/matrix/utils/matAlgo05xSfSf.js");
var _matrixAlgorithmSuite = require("../../type/matrix/utils/matrixAlgorithmSuite.js");
var _compareUnits = require("./compareUnits.js");
const name = 'compare';
const dependencies = ['typed', 'config', 'matrix', 'equalScalar', 'BigNumber', 'Fraction', 'DenseMatrix', 'concat'];
const createCompare = exports.createCompare = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
let {
typed,
config,
equalScalar,
matrix,
BigNumber,
Fraction,
DenseMatrix,
concat
} = _ref;
const matAlgo03xDSf = (0, _matAlgo03xDSf.createMatAlgo03xDSf)({
typed
});
const matAlgo05xSfSf = (0, _matAlgo05xSfSf.createMatAlgo05xSfSf)({
typed,
equalScalar
});
const matAlgo12xSfs = (0, _matAlgo12xSfs.createMatAlgo12xSfs)({
typed,
DenseMatrix
});
const matrixAlgorithmSuite = (0, _matrixAlgorithmSuite.createMatrixAlgorithmSuite)({
typed,
matrix,
concat
});
const compareUnits = (0, _compareUnits.createCompareUnits)({
typed
});
/**
* Compare two values. Returns 1 when x > y, -1 when x < y, and 0 when x == y.
*
* x and y are considered equal when the relative difference between x and y
* is smaller than the configured absTol and relTol. The function cannot be used to
* compare values smaller than approximately 2.22e-16.
*
* For matrices, the function is evaluated element wise.
* Strings are compared by their numerical value.
*
* Syntax:
*
* math.compare(x, y)
*
* Examples:
*
* math.compare(6, 1) // returns 1
* math.compare(2, 3) // returns -1
* math.compare(7, 7) // returns 0
* math.compare('10', '2') // returns 1
* math.compare('1000', '1e3') // returns 0
*
* const a = math.unit('5 cm')
* const b = math.unit('40 mm')
* math.compare(a, b) // returns 1
*
* math.compare(2, [1, 2, 3]) // returns [1, 0, -1]
*
* See also:
*
* equal, unequal, smaller, smallerEq, larger, largerEq, compareNatural, compareText
*
* @param {number | BigNumber | bigint | Fraction | Unit | string | Array | Matrix} x First value to compare
* @param {number | BigNumber | bigint | Fraction | Unit | string | Array | Matrix} y Second value to compare
* @return {number | BigNumber | bigint | Fraction | Array | Matrix} Returns the result of the comparison:
* 1 when x > y, -1 when x < y, and 0 when x == y.
*/
return typed(name, createCompareNumber({
typed,
config
}), {
'boolean, boolean': function (x, y) {
return x === y ? 0 : x > y ? 1 : -1;
},
'BigNumber, BigNumber': function (x, y) {
return (0, _nearlyEqual.nearlyEqual)(x, y, config.relTol, config.absTol) ? new BigNumber(0) : new BigNumber(x.cmp(y));
},
'bigint, bigint': function (x, y) {
return x === y ? 0n : x > y ? 1n : -1n;
},
'Fraction, Fraction': function (x, y) {
return new Fraction(x.compare(y));
},
'Complex, Complex': function () {
throw new TypeError('No ordering relation is defined for complex numbers');
}
}, compareUnits, matrixAlgorithmSuite({
SS: matAlgo05xSfSf,
DS: matAlgo03xDSf,
Ss: matAlgo12xSfs
}));
});
const createCompareNumber = exports.createCompareNumber = /* #__PURE__ */(0, _factory.factory)(name, ['typed', 'config'], _ref2 => {
let {
typed,
config
} = _ref2;
return typed(name, {
'number, number': function (x, y) {
return (0, _number.nearlyEqual)(x, y, config.relTol, config.absTol) ? 0 : x > y ? 1 : -1;
}
});
});

View File

@@ -0,0 +1,281 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createCompareNatural = void 0;
var _javascriptNaturalSort = _interopRequireDefault(require("javascript-natural-sort"));
var _is = require("../../utils/is.js");
var _factory = require("../../utils/factory.js");
const name = 'compareNatural';
const dependencies = ['typed', 'compare'];
const createCompareNatural = exports.createCompareNatural = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
let {
typed,
compare
} = _ref;
const compareBooleans = compare.signatures['boolean,boolean'];
/**
* Compare two values of any type in a deterministic, natural way.
*
* For numeric values, the function works the same as `math.compare`.
* For types of values that can't be compared mathematically,
* the function compares in a natural way.
*
* For numeric values, x and y are considered equal when the relative
* difference between x and y is smaller than the configured relTol and absTol.
* The function cannot be used to compare values smaller than
* approximately 2.22e-16.
*
* For Complex numbers, first the real parts are compared. If equal,
* the imaginary parts are compared.
*
* Strings are compared with a natural sorting algorithm, which
* orders strings in a "logic" way following some heuristics.
* This differs from the function `compare`, which converts the string
* into a numeric value and compares that. The function `compareText`
* on the other hand compares text lexically.
*
* Arrays and Matrices are compared value by value until there is an
* unequal pair of values encountered. Objects are compared by sorted
* keys until the keys or their values are unequal.
*
* Syntax:
*
* math.compareNatural(x, y)
*
* Examples:
*
* math.compareNatural(6, 1) // returns 1
* math.compareNatural(2, 3) // returns -1
* math.compareNatural(7, 7) // returns 0
*
* math.compareNatural('10', '2') // returns 1
* math.compareText('10', '2') // returns -1
* math.compare('10', '2') // returns 1
*
* math.compareNatural('Answer: 10', 'Answer: 2') // returns 1
* math.compareText('Answer: 10', 'Answer: 2') // returns -1
* math.compare('Answer: 10', 'Answer: 2')
* // Error: Cannot convert "Answer: 10" to a number
*
* const a = math.unit('5 cm')
* const b = math.unit('40 mm')
* math.compareNatural(a, b) // returns 1
*
* const c = math.complex('2 + 3i')
* const d = math.complex('2 + 4i')
* math.compareNatural(c, d) // returns -1
*
* math.compareNatural([1, 2, 4], [1, 2, 3]) // returns 1
* math.compareNatural([1, 2, 3], [1, 2]) // returns 1
* math.compareNatural([1, 5], [1, 2, 3]) // returns 1
* math.compareNatural([1, 2], [1, 2]) // returns 0
*
* math.compareNatural({a: 2}, {a: 4}) // returns -1
*
* See also:
*
* compare, compareText
*
* @param {*} x First value to compare
* @param {*} y Second value to compare
* @return {number} Returns the result of the comparison:
* 1 when x > y, -1 when x < y, and 0 when x == y.
*/
return typed(name, {
'any, any': _compareNatural
}); // just to check # args
function _compareNatural(x, y) {
const typeX = (0, _is.typeOf)(x);
const typeY = (0, _is.typeOf)(y);
let c;
// numeric types
if ((typeX === 'number' || typeX === 'BigNumber' || typeX === 'Fraction') && (typeY === 'number' || typeY === 'BigNumber' || typeY === 'Fraction')) {
c = compare(x, y);
if (c.toString() !== '0') {
// c can be number, BigNumber, or Fraction
return c > 0 ? 1 : -1; // return a number
} else {
return (0, _javascriptNaturalSort.default)(typeX, typeY);
}
}
// matrix types
const matTypes = ['Array', 'DenseMatrix', 'SparseMatrix'];
if (matTypes.includes(typeX) || matTypes.includes(typeY)) {
c = compareMatricesAndArrays(_compareNatural, x, y);
if (c !== 0) {
return c;
} else {
return (0, _javascriptNaturalSort.default)(typeX, typeY);
}
}
// in case of different types, order by name of type, i.e. 'BigNumber' < 'Complex'
if (typeX !== typeY) {
return (0, _javascriptNaturalSort.default)(typeX, typeY);
}
if (typeX === 'Complex') {
return compareComplexNumbers(x, y);
}
if (typeX === 'Unit') {
if (x.equalBase(y)) {
return _compareNatural(x.value, y.value);
}
// compare by units
return compareArrays(_compareNatural, x.formatUnits(), y.formatUnits());
}
if (typeX === 'boolean') {
return compareBooleans(x, y);
}
if (typeX === 'string') {
return (0, _javascriptNaturalSort.default)(x, y);
}
if (typeX === 'Object') {
return compareObjects(_compareNatural, x, y);
}
if (typeX === 'null') {
return 0;
}
if (typeX === 'undefined') {
return 0;
}
// this should not occur...
throw new TypeError('Unsupported type of value "' + typeX + '"');
}
/**
* Compare mixed matrix/array types, by converting to same-shaped array.
* This comparator is non-deterministic regarding input types.
* @param {Array | SparseMatrix | DenseMatrix | *} x
* @param {Array | SparseMatrix | DenseMatrix | *} y
* @returns {number} Returns the comparison result: -1, 0, or 1
*/
function compareMatricesAndArrays(compareNatural, x, y) {
if ((0, _is.isSparseMatrix)(x) && (0, _is.isSparseMatrix)(y)) {
return compareArrays(compareNatural, x.toJSON().values, y.toJSON().values);
}
if ((0, _is.isSparseMatrix)(x)) {
// note: convert to array is expensive
return compareMatricesAndArrays(compareNatural, x.toArray(), y);
}
if ((0, _is.isSparseMatrix)(y)) {
// note: convert to array is expensive
return compareMatricesAndArrays(compareNatural, x, y.toArray());
}
// convert DenseArray into Array
if ((0, _is.isDenseMatrix)(x)) {
return compareMatricesAndArrays(compareNatural, x.toJSON().data, y);
}
if ((0, _is.isDenseMatrix)(y)) {
return compareMatricesAndArrays(compareNatural, x, y.toJSON().data);
}
// convert scalars to array
if (!Array.isArray(x)) {
return compareMatricesAndArrays(compareNatural, [x], y);
}
if (!Array.isArray(y)) {
return compareMatricesAndArrays(compareNatural, x, [y]);
}
return compareArrays(compareNatural, x, y);
}
/**
* Compare two Arrays
*
* - First, compares value by value
* - Next, if all corresponding values are equal,
* look at the length: longest array will be considered largest
*
* @param {Array} x
* @param {Array} y
* @returns {number} Returns the comparison result: -1, 0, or 1
*/
function compareArrays(compareNatural, x, y) {
// compare each value
for (let i = 0, ii = Math.min(x.length, y.length); i < ii; i++) {
const v = compareNatural(x[i], y[i]);
if (v !== 0) {
return v;
}
}
// compare the size of the arrays
if (x.length > y.length) {
return 1;
}
if (x.length < y.length) {
return -1;
}
// both Arrays have equal size and content
return 0;
}
/**
* Compare two objects
*
* - First, compare sorted property names
* - Next, compare the property values
*
* @param {Object} x
* @param {Object} y
* @returns {number} Returns the comparison result: -1, 0, or 1
*/
function compareObjects(compareNatural, x, y) {
const keysX = Object.keys(x);
const keysY = Object.keys(y);
// compare keys
keysX.sort(_javascriptNaturalSort.default);
keysY.sort(_javascriptNaturalSort.default);
const c = compareArrays(compareNatural, keysX, keysY);
if (c !== 0) {
return c;
}
// compare values
for (let i = 0; i < keysX.length; i++) {
const v = compareNatural(x[keysX[i]], y[keysY[i]]);
if (v !== 0) {
return v;
}
}
return 0;
}
});
/**
* Compare two complex numbers, `x` and `y`:
*
* - First, compare the real values of `x` and `y`
* - If equal, compare the imaginary values of `x` and `y`
*
* @params {Complex} x
* @params {Complex} y
* @returns {number} Returns the comparison result: -1, 0, or 1
*/
function compareComplexNumbers(x, y) {
if (x.re > y.re) {
return 1;
}
if (x.re < y.re) {
return -1;
}
if (x.im > y.im) {
return 1;
}
if (x.im < y.im) {
return -1;
}
return 0;
}

View File

@@ -0,0 +1,63 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createCompareTextNumber = exports.createCompareText = void 0;
var _string = require("../../utils/string.js");
var _factory = require("../../utils/factory.js");
var _matrixAlgorithmSuite = require("../../type/matrix/utils/matrixAlgorithmSuite.js");
const name = 'compareText';
const dependencies = ['typed', 'matrix', 'concat'];
_string.compareText.signature = 'any, any';
const createCompareText = exports.createCompareText = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
let {
typed,
matrix,
concat
} = _ref;
const matrixAlgorithmSuite = (0, _matrixAlgorithmSuite.createMatrixAlgorithmSuite)({
typed,
matrix,
concat
});
/**
* Compare two strings lexically. Comparison is case sensitive.
* Returns 1 when x > y, -1 when x < y, and 0 when x == y.
*
* For matrices, the function is evaluated element wise.
*
* Syntax:
*
* math.compareText(x, y)
*
* Examples:
*
* math.compareText('B', 'A') // returns 1
* math.compareText('2', '10') // returns 1
* math.compare('2', '10') // returns -1
* math.compareNatural('2', '10') // returns -1
*
* math.compareText('B', ['A', 'B', 'C']) // returns [1, 0, -1]
*
* See also:
*
* equal, equalText, compare, compareNatural
*
* @param {string | Array | DenseMatrix} x First string to compare
* @param {string | Array | DenseMatrix} y Second string to compare
* @return {number | Array | DenseMatrix} Returns the result of the comparison:
* 1 when x > y, -1 when x < y, and 0 when x == y.
*/
return typed(name, _string.compareText, matrixAlgorithmSuite({
elop: _string.compareText,
Ds: true
}));
});
const createCompareTextNumber = exports.createCompareTextNumber = /* #__PURE__ */(0, _factory.factory)(name, ['typed'], _ref2 => {
let {
typed
} = _ref2;
return typed(name, _string.compareText);
});

View File

@@ -0,0 +1,20 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createCompareUnits = void 0;
var _factory = require("../../utils/factory.js");
const createCompareUnits = exports.createCompareUnits = /* #__PURE__ */(0, _factory.factory)('compareUnits', ['typed'], _ref => {
let {
typed
} = _ref;
return {
'Unit, Unit': typed.referToSelf(self => (x, y) => {
if (!x.equalBase(y)) {
throw new Error('Cannot compare units with different base');
}
return typed.find(self, [x.valueType(), y.valueType()])(x.value, y.value);
})
};
});

View File

@@ -0,0 +1,80 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createDeepEqual = void 0;
var _factory = require("../../utils/factory.js");
const name = 'deepEqual';
const dependencies = ['typed', 'equal'];
const createDeepEqual = exports.createDeepEqual = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
let {
typed,
equal
} = _ref;
/**
* Test element wise whether two matrices are equal.
* The function accepts both matrices and scalar values.
*
* Strings are compared by their numerical value.
*
* Syntax:
*
* math.deepEqual(x, y)
*
* Examples:
*
* math.deepEqual(2, 4) // returns false
*
* a = [2, 5, 1]
* b = [2, 7, 1]
*
* math.deepEqual(a, b) // returns false
* math.equal(a, b) // returns [true, false, true]
*
* See also:
*
* equal, unequal
*
* @param {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} x First matrix to compare
* @param {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} y Second matrix to compare
* @return {number | BigNumber | Fraction | Complex | Unit | Array | Matrix}
* Returns true when the input matrices have the same size and each of their elements is equal.
*/
return typed(name, {
'any, any': function (x, y) {
return _deepEqual(x.valueOf(), y.valueOf());
}
});
/**
* Test whether two arrays have the same size and all elements are equal
* @param {Array | *} x
* @param {Array | *} y
* @return {boolean} Returns true if both arrays are deep equal
*/
function _deepEqual(x, y) {
if (Array.isArray(x)) {
if (Array.isArray(y)) {
const len = x.length;
if (len !== y.length) {
return false;
}
for (let i = 0; i < len; i++) {
if (!_deepEqual(x[i], y[i])) {
return false;
}
}
return true;
} else {
return false;
}
} else {
if (Array.isArray(y)) {
return false;
} else {
return equal(x, y);
}
}
}
});

View File

@@ -0,0 +1,116 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createEqualNumber = exports.createEqual = void 0;
var _factory = require("../../utils/factory.js");
var _matAlgo03xDSf = require("../../type/matrix/utils/matAlgo03xDSf.js");
var _matAlgo07xSSf = require("../../type/matrix/utils/matAlgo07xSSf.js");
var _matAlgo12xSfs = require("../../type/matrix/utils/matAlgo12xSfs.js");
var _matrixAlgorithmSuite = require("../../type/matrix/utils/matrixAlgorithmSuite.js");
const name = 'equal';
const dependencies = ['typed', 'matrix', 'equalScalar', 'DenseMatrix', 'concat'];
const createEqual = exports.createEqual = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
let {
typed,
matrix,
equalScalar,
DenseMatrix,
concat
} = _ref;
const matAlgo03xDSf = (0, _matAlgo03xDSf.createMatAlgo03xDSf)({
typed
});
const matAlgo07xSSf = (0, _matAlgo07xSSf.createMatAlgo07xSSf)({
typed,
DenseMatrix
});
const matAlgo12xSfs = (0, _matAlgo12xSfs.createMatAlgo12xSfs)({
typed,
DenseMatrix
});
const matrixAlgorithmSuite = (0, _matrixAlgorithmSuite.createMatrixAlgorithmSuite)({
typed,
matrix,
concat
});
/**
* Test whether two values are equal.
*
* The function tests whether the relative difference between x and y is
* smaller than the configured relTol and absTol. The function cannot be used to
* compare values smaller than approximately 2.22e-16.
*
* For matrices, the function is evaluated element wise.
* In case of complex numbers, x.re must equal y.re, and x.im must equal y.im.
*
* Values `null` and `undefined` are compared strictly, thus `null` is only
* equal to `null` and nothing else, and `undefined` is only equal to
* `undefined` and nothing else. Strings are compared by their numerical value.
*
* Syntax:
*
* math.equal(x, y)
*
* Examples:
*
* math.equal(2 + 2, 3) // returns false
* math.equal(2 + 2, 4) // returns true
*
* const a = math.unit('50 cm')
* const b = math.unit('5 m')
* math.equal(a, b) // returns true
*
* const c = [2, 5, 1]
* const d = [2, 7, 1]
*
* math.equal(c, d) // returns [true, false, true]
* math.deepEqual(c, d) // returns false
*
* math.equal("1000", "1e3") // returns true
* math.equal(0, null) // returns false
*
* See also:
*
* unequal, smaller, smallerEq, larger, largerEq, compare, deepEqual, equalText
*
* @param {number | BigNumber | bigint | boolean | Complex | Unit | string | Array | Matrix} x First value to compare
* @param {number | BigNumber | bigint | boolean | Complex | Unit | string | Array | Matrix} y Second value to compare
* @return {boolean | Array | Matrix} Returns true when the compared values are equal, else returns false
*/
return typed(name, createEqualNumber({
typed,
equalScalar
}), matrixAlgorithmSuite({
elop: equalScalar,
SS: matAlgo07xSSf,
DS: matAlgo03xDSf,
Ss: matAlgo12xSfs
}));
});
const createEqualNumber = exports.createEqualNumber = (0, _factory.factory)(name, ['typed', 'equalScalar'], _ref2 => {
let {
typed,
equalScalar
} = _ref2;
return typed(name, {
'any, any': function (x, y) {
// strict equality for null and undefined?
if (x === null) {
return y === null;
}
if (y === null) {
return x === null;
}
if (x === undefined) {
return y === undefined;
}
if (y === undefined) {
return x === undefined;
}
return equalScalar(x, y);
}
});
});

View File

@@ -0,0 +1,62 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createEqualScalarNumber = exports.createEqualScalar = void 0;
var _nearlyEqual = require("../../utils/bignumber/nearlyEqual.js");
var _number = require("../../utils/number.js");
var _factory = require("../../utils/factory.js");
var _complex = require("../../utils/complex.js");
var _compareUnits = require("./compareUnits.js");
const name = 'equalScalar';
const dependencies = ['typed', 'config'];
const createEqualScalar = exports.createEqualScalar = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
let {
typed,
config
} = _ref;
const compareUnits = (0, _compareUnits.createCompareUnits)({
typed
});
/**
* Test whether two scalar values are nearly equal.
*
* @param {number | BigNumber | bigint | Fraction | boolean | Complex | Unit} x First value to compare
* @param {number | BigNumber | bigint | Fraction | boolean | Complex} y Second value to compare
* @return {boolean} Returns true when the compared values are equal, else returns false
* @private
*/
return typed(name, {
'boolean, boolean': function (x, y) {
return x === y;
},
'number, number': function (x, y) {
return (0, _number.nearlyEqual)(x, y, config.relTol, config.absTol);
},
'BigNumber, BigNumber': function (x, y) {
return x.eq(y) || (0, _nearlyEqual.nearlyEqual)(x, y, config.relTol, config.absTol);
},
'bigint, bigint': function (x, y) {
return x === y;
},
'Fraction, Fraction': function (x, y) {
return x.equals(y);
},
'Complex, Complex': function (x, y) {
return (0, _complex.complexEquals)(x, y, config.relTol, config.absTol);
}
}, compareUnits);
});
const createEqualScalarNumber = exports.createEqualScalarNumber = (0, _factory.factory)(name, ['typed', 'config'], _ref2 => {
let {
typed,
config
} = _ref2;
return typed(name, {
'number, number': function (x, y) {
return (0, _number.nearlyEqual)(x, y, config.relTol, config.absTol);
}
});
});

View File

@@ -0,0 +1,47 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createEqualText = void 0;
var _factory = require("../../utils/factory.js");
const name = 'equalText';
const dependencies = ['typed', 'compareText', 'isZero'];
const createEqualText = exports.createEqualText = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
let {
typed,
compareText,
isZero
} = _ref;
/**
* Check equality of two strings. Comparison is case sensitive.
*
* For matrices, the function is evaluated element wise.
*
* Syntax:
*
* math.equalText(x, y)
*
* Examples:
*
* math.equalText('Hello', 'Hello') // returns true
* math.equalText('a', 'A') // returns false
* math.equal('2e3', '2000') // returns true
* math.equalText('2e3', '2000') // returns false
*
* math.equalText('B', ['A', 'B', 'C']) // returns [false, true, false]
*
* See also:
*
* equal, compareText, compare, compareNatural
*
* @param {string | Array | DenseMatrix} x First string to compare
* @param {string | Array | DenseMatrix} y Second string to compare
* @return {number | Array | DenseMatrix} Returns true if the values are equal, and false if not.
*/
return typed(name, {
'any, any': function (x, y) {
return isZero(compareText(x, y));
}
});
});

View File

@@ -0,0 +1,105 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createLargerNumber = exports.createLarger = void 0;
var _nearlyEqual = require("../../utils/bignumber/nearlyEqual.js");
var _number = require("../../utils/number.js");
var _factory = require("../../utils/factory.js");
var _matAlgo03xDSf = require("../../type/matrix/utils/matAlgo03xDSf.js");
var _matAlgo07xSSf = require("../../type/matrix/utils/matAlgo07xSSf.js");
var _matAlgo12xSfs = require("../../type/matrix/utils/matAlgo12xSfs.js");
var _matrixAlgorithmSuite = require("../../type/matrix/utils/matrixAlgorithmSuite.js");
var _compareUnits = require("./compareUnits.js");
const name = 'larger';
const dependencies = ['typed', 'config', 'matrix', 'DenseMatrix', 'concat'];
const createLarger = exports.createLarger = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
let {
typed,
config,
matrix,
DenseMatrix,
concat
} = _ref;
const matAlgo03xDSf = (0, _matAlgo03xDSf.createMatAlgo03xDSf)({
typed
});
const matAlgo07xSSf = (0, _matAlgo07xSSf.createMatAlgo07xSSf)({
typed,
DenseMatrix
});
const matAlgo12xSfs = (0, _matAlgo12xSfs.createMatAlgo12xSfs)({
typed,
DenseMatrix
});
const matrixAlgorithmSuite = (0, _matrixAlgorithmSuite.createMatrixAlgorithmSuite)({
typed,
matrix,
concat
});
const compareUnits = (0, _compareUnits.createCompareUnits)({
typed
});
/**
* Test whether value x is larger than y.
*
* The function returns true when x is larger than y and the relative
* difference between x and y is larger than the configured relTol and absTol. The
* function cannot be used to compare values smaller than approximately 2.22e-16.
*
* For matrices, the function is evaluated element wise.
* Strings are compared by their numerical value.
*
* Syntax:
*
* math.larger(x, y)
*
* Examples:
*
* math.larger(2, 3) // returns false
* math.larger(5, 2 + 2) // returns true
*
* const a = math.unit('5 cm')
* const b = math.unit('2 inch')
* math.larger(a, b) // returns false
*
* See also:
*
* equal, unequal, smaller, smallerEq, largerEq, compare
*
* @param {number | BigNumber | bigint | Fraction | boolean | Unit | string | Array | Matrix} x First value to compare
* @param {number | BigNumber | bigint | Fraction | boolean | Unit | string | Array | Matrix} y Second value to compare
* @return {boolean | Array | Matrix} Returns true when the x is larger than y, else returns false
*/
return typed(name, createLargerNumber({
typed,
config
}), {
'boolean, boolean': (x, y) => x > y,
'BigNumber, BigNumber': function (x, y) {
return x.gt(y) && !(0, _nearlyEqual.nearlyEqual)(x, y, config.relTol, config.absTol);
},
'bigint, bigint': (x, y) => x > y,
'Fraction, Fraction': (x, y) => x.compare(y) === 1,
'Complex, Complex': function () {
throw new TypeError('No ordering relation is defined for complex numbers');
}
}, compareUnits, matrixAlgorithmSuite({
SS: matAlgo07xSSf,
DS: matAlgo03xDSf,
Ss: matAlgo12xSfs
}));
});
const createLargerNumber = exports.createLargerNumber = /* #__PURE__ */(0, _factory.factory)(name, ['typed', 'config'], _ref2 => {
let {
typed,
config
} = _ref2;
return typed(name, {
'number, number': function (x, y) {
return x > y && !(0, _number.nearlyEqual)(x, y, config.relTol, config.absTol);
}
});
});

View File

@@ -0,0 +1,103 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createLargerEqNumber = exports.createLargerEq = void 0;
var _nearlyEqual = require("../../utils/bignumber/nearlyEqual.js");
var _number = require("../../utils/number.js");
var _factory = require("../../utils/factory.js");
var _matAlgo03xDSf = require("../../type/matrix/utils/matAlgo03xDSf.js");
var _matAlgo07xSSf = require("../../type/matrix/utils/matAlgo07xSSf.js");
var _matAlgo12xSfs = require("../../type/matrix/utils/matAlgo12xSfs.js");
var _matrixAlgorithmSuite = require("../../type/matrix/utils/matrixAlgorithmSuite.js");
var _compareUnits = require("./compareUnits.js");
const name = 'largerEq';
const dependencies = ['typed', 'config', 'matrix', 'DenseMatrix', 'concat'];
const createLargerEq = exports.createLargerEq = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
let {
typed,
config,
matrix,
DenseMatrix,
concat
} = _ref;
const matAlgo03xDSf = (0, _matAlgo03xDSf.createMatAlgo03xDSf)({
typed
});
const matAlgo07xSSf = (0, _matAlgo07xSSf.createMatAlgo07xSSf)({
typed,
DenseMatrix
});
const matAlgo12xSfs = (0, _matAlgo12xSfs.createMatAlgo12xSfs)({
typed,
DenseMatrix
});
const matrixAlgorithmSuite = (0, _matrixAlgorithmSuite.createMatrixAlgorithmSuite)({
typed,
matrix,
concat
});
const compareUnits = (0, _compareUnits.createCompareUnits)({
typed
});
/**
* Test whether value x is larger or equal to y.
*
* The function returns true when x is larger than y or the relative
* difference between x and y is smaller than the configured relTol and absTol. The
* function cannot be used to compare values smaller than approximately 2.22e-16.
*
* For matrices, the function is evaluated element wise.
* Strings are compared by their numerical value.
*
* Syntax:
*
* math.largerEq(x, y)
*
* Examples:
*
* math.larger(2, 1 + 1) // returns false
* math.largerEq(2, 1 + 1) // returns true
*
* See also:
*
* equal, unequal, smaller, smallerEq, larger, compare
*
* @param {number | BigNumber | bigint | Fraction | boolean | Unit | string | Array | Matrix} x First value to compare
* @param {number | BigNumber | bigint | Fraction | boolean | Unit | string | Array | Matrix} y Second value to compare
* @return {boolean | Array | Matrix} Returns true when the x is larger or equal to y, else returns false
*/
return typed(name, createLargerEqNumber({
typed,
config
}), {
'boolean, boolean': (x, y) => x >= y,
'BigNumber, BigNumber': function (x, y) {
return x.gte(y) || (0, _nearlyEqual.nearlyEqual)(x, y, config.relTol, config.absTol);
},
'bigint, bigint': function (x, y) {
return x >= y;
},
'Fraction, Fraction': (x, y) => x.compare(y) !== -1,
'Complex, Complex': function () {
throw new TypeError('No ordering relation is defined for complex numbers');
}
}, compareUnits, matrixAlgorithmSuite({
SS: matAlgo07xSSf,
DS: matAlgo03xDSf,
Ss: matAlgo12xSfs
}));
});
const createLargerEqNumber = exports.createLargerEqNumber = /* #__PURE__ */(0, _factory.factory)(name, ['typed', 'config'], _ref2 => {
let {
typed,
config
} = _ref2;
return typed(name, {
'number, number': function (x, y) {
return x >= y || (0, _number.nearlyEqual)(x, y, config.relTol, config.absTol);
}
});
});

View File

@@ -0,0 +1,105 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createSmallerNumber = exports.createSmaller = void 0;
var _nearlyEqual = require("../../utils/bignumber/nearlyEqual.js");
var _number = require("../../utils/number.js");
var _factory = require("../../utils/factory.js");
var _matAlgo03xDSf = require("../../type/matrix/utils/matAlgo03xDSf.js");
var _matAlgo07xSSf = require("../../type/matrix/utils/matAlgo07xSSf.js");
var _matAlgo12xSfs = require("../../type/matrix/utils/matAlgo12xSfs.js");
var _matrixAlgorithmSuite = require("../../type/matrix/utils/matrixAlgorithmSuite.js");
var _compareUnits = require("./compareUnits.js");
const name = 'smaller';
const dependencies = ['typed', 'config', 'matrix', 'DenseMatrix', 'concat'];
const createSmaller = exports.createSmaller = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
let {
typed,
config,
matrix,
DenseMatrix,
concat
} = _ref;
const matAlgo03xDSf = (0, _matAlgo03xDSf.createMatAlgo03xDSf)({
typed
});
const matAlgo07xSSf = (0, _matAlgo07xSSf.createMatAlgo07xSSf)({
typed,
DenseMatrix
});
const matAlgo12xSfs = (0, _matAlgo12xSfs.createMatAlgo12xSfs)({
typed,
DenseMatrix
});
const matrixAlgorithmSuite = (0, _matrixAlgorithmSuite.createMatrixAlgorithmSuite)({
typed,
matrix,
concat
});
const compareUnits = (0, _compareUnits.createCompareUnits)({
typed
});
/**
* Test whether value x is smaller than y.
*
* The function returns true when x is smaller than y and the relative
* difference between x and y is smaller than the configured relTol and absTol. The
* function cannot be used to compare values smaller than approximately 2.22e-16.
*
* For matrices, the function is evaluated element wise.
* Strings are compared by their numerical value.
*
* Syntax:
*
* math.smaller(x, y)
*
* Examples:
*
* math.smaller(2, 3) // returns true
* math.smaller(5, 2 * 2) // returns false
*
* const a = math.unit('5 cm')
* const b = math.unit('2 inch')
* math.smaller(a, b) // returns true
*
* See also:
*
* equal, unequal, smallerEq, smaller, smallerEq, compare
*
* @param {number | BigNumber | bigint | Fraction | boolean | Unit | string | Array | Matrix} x First value to compare
* @param {number | BigNumber | bigint | Fraction | boolean | Unit | string | Array | Matrix} y Second value to compare
* @return {boolean | Array | Matrix} Returns true when the x is smaller than y, else returns false
*/
return typed(name, createSmallerNumber({
typed,
config
}), {
'boolean, boolean': (x, y) => x < y,
'BigNumber, BigNumber': function (x, y) {
return x.lt(y) && !(0, _nearlyEqual.nearlyEqual)(x, y, config.relTol, config.absTol);
},
'bigint, bigint': (x, y) => x < y,
'Fraction, Fraction': (x, y) => x.compare(y) === -1,
'Complex, Complex': function (x, y) {
throw new TypeError('No ordering relation is defined for complex numbers');
}
}, compareUnits, matrixAlgorithmSuite({
SS: matAlgo07xSSf,
DS: matAlgo03xDSf,
Ss: matAlgo12xSfs
}));
});
const createSmallerNumber = exports.createSmallerNumber = /* #__PURE__ */(0, _factory.factory)(name, ['typed', 'config'], _ref2 => {
let {
typed,
config
} = _ref2;
return typed(name, {
'number, number': function (x, y) {
return x < y && !(0, _number.nearlyEqual)(x, y, config.relTol, config.absTol);
}
});
});

View File

@@ -0,0 +1,101 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createSmallerEqNumber = exports.createSmallerEq = void 0;
var _nearlyEqual = require("../../utils/bignumber/nearlyEqual.js");
var _number = require("../../utils/number.js");
var _factory = require("../../utils/factory.js");
var _matAlgo03xDSf = require("../../type/matrix/utils/matAlgo03xDSf.js");
var _matAlgo07xSSf = require("../../type/matrix/utils/matAlgo07xSSf.js");
var _matAlgo12xSfs = require("../../type/matrix/utils/matAlgo12xSfs.js");
var _matrixAlgorithmSuite = require("../../type/matrix/utils/matrixAlgorithmSuite.js");
var _compareUnits = require("./compareUnits.js");
const name = 'smallerEq';
const dependencies = ['typed', 'config', 'matrix', 'DenseMatrix', 'concat'];
const createSmallerEq = exports.createSmallerEq = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
let {
typed,
config,
matrix,
DenseMatrix,
concat
} = _ref;
const matAlgo03xDSf = (0, _matAlgo03xDSf.createMatAlgo03xDSf)({
typed
});
const matAlgo07xSSf = (0, _matAlgo07xSSf.createMatAlgo07xSSf)({
typed,
DenseMatrix
});
const matAlgo12xSfs = (0, _matAlgo12xSfs.createMatAlgo12xSfs)({
typed,
DenseMatrix
});
const matrixAlgorithmSuite = (0, _matrixAlgorithmSuite.createMatrixAlgorithmSuite)({
typed,
matrix,
concat
});
const compareUnits = (0, _compareUnits.createCompareUnits)({
typed
});
/**
* Test whether value x is smaller or equal to y.
*
* The function returns true when x is smaller than y or the relative
* difference between x and y is smaller than the configured relTol and absTol. The
* function cannot be used to compare values smaller than approximately 2.22e-16.
*
* For matrices, the function is evaluated element wise.
* Strings are compared by their numerical value.
*
* Syntax:
*
* math.smallerEq(x, y)
*
* Examples:
*
* math.smaller(1 + 2, 3) // returns false
* math.smallerEq(1 + 2, 3) // returns true
*
* See also:
*
* equal, unequal, smaller, larger, largerEq, compare
*
* @param {number | BigNumber | bigint | Fraction | boolean | Unit | string | Array | Matrix} x First value to compare
* @param {number | BigNumber | bigint | Fraction | boolean | Unit | string | Array | Matrix} y Second value to compare
* @return {boolean | Array | Matrix} Returns true when the x is smaller than y, else returns false
*/
return typed(name, createSmallerEqNumber({
typed,
config
}), {
'boolean, boolean': (x, y) => x <= y,
'BigNumber, BigNumber': function (x, y) {
return x.lte(y) || (0, _nearlyEqual.nearlyEqual)(x, y, config.relTol, config.absTol);
},
'bigint, bigint': (x, y) => x <= y,
'Fraction, Fraction': (x, y) => x.compare(y) !== 1,
'Complex, Complex': function () {
throw new TypeError('No ordering relation is defined for complex numbers');
}
}, compareUnits, matrixAlgorithmSuite({
SS: matAlgo07xSSf,
DS: matAlgo03xDSf,
Ss: matAlgo12xSfs
}));
});
const createSmallerEqNumber = exports.createSmallerEqNumber = /* #__PURE__ */(0, _factory.factory)(name, ['typed', 'config'], _ref2 => {
let {
typed,
config
} = _ref2;
return typed(name, {
'number, number': function (x, y) {
return x <= y || (0, _number.nearlyEqual)(x, y, config.relTol, config.absTol);
}
});
});

View File

@@ -0,0 +1,119 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createUnequalNumber = exports.createUnequal = void 0;
var _factory = require("../../utils/factory.js");
var _matAlgo03xDSf = require("../../type/matrix/utils/matAlgo03xDSf.js");
var _matAlgo07xSSf = require("../../type/matrix/utils/matAlgo07xSSf.js");
var _matAlgo12xSfs = require("../../type/matrix/utils/matAlgo12xSfs.js");
var _matrixAlgorithmSuite = require("../../type/matrix/utils/matrixAlgorithmSuite.js");
const name = 'unequal';
const dependencies = ['typed', 'config', 'equalScalar', 'matrix', 'DenseMatrix', 'concat'];
const createUnequal = exports.createUnequal = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
let {
typed,
config,
equalScalar,
matrix,
DenseMatrix,
concat
} = _ref;
const matAlgo03xDSf = (0, _matAlgo03xDSf.createMatAlgo03xDSf)({
typed
});
const matAlgo07xSSf = (0, _matAlgo07xSSf.createMatAlgo07xSSf)({
typed,
DenseMatrix
});
const matAlgo12xSfs = (0, _matAlgo12xSfs.createMatAlgo12xSfs)({
typed,
DenseMatrix
});
const matrixAlgorithmSuite = (0, _matrixAlgorithmSuite.createMatrixAlgorithmSuite)({
typed,
matrix,
concat
});
/**
* Test whether two values are unequal.
*
* The function tests whether the relative difference between x and y is
* larger than the configured relTol and absTol. The function cannot be used to compare
* values smaller than approximately 2.22e-16.
*
* For matrices, the function is evaluated element wise.
* In case of complex numbers, x.re must unequal y.re, or x.im must unequal y.im.
* Strings are compared by their numerical value.
*
* Values `null` and `undefined` are compared strictly, thus `null` is unequal
* with everything except `null`, and `undefined` is unequal with everything
* except `undefined`.
*
* Syntax:
*
* math.unequal(x, y)
*
* Examples:
*
* math.unequal(2 + 2, 3) // returns true
* math.unequal(2 + 2, 4) // returns false
*
* const a = math.unit('50 cm')
* const b = math.unit('5 m')
* math.unequal(a, b) // returns false
*
* const c = [2, 5, 1]
* const d = [2, 7, 1]
*
* math.unequal(c, d) // returns [false, true, false]
* math.deepEqual(c, d) // returns false
*
* math.unequal(0, null) // returns true
* See also:
*
* equal, deepEqual, smaller, smallerEq, larger, largerEq, compare
*
* @param {number | BigNumber | Fraction | boolean | Complex | Unit | string | Array | Matrix | undefined} x First value to compare
* @param {number | BigNumber | Fraction | boolean | Complex | Unit | string | Array | Matrix | undefined} y Second value to compare
* @return {boolean | Array | Matrix} Returns true when the compared values are unequal, else returns false
*/
return typed(name, createUnequalNumber({
typed,
equalScalar
}), matrixAlgorithmSuite({
elop: _unequal,
SS: matAlgo07xSSf,
DS: matAlgo03xDSf,
Ss: matAlgo12xSfs
}));
function _unequal(x, y) {
return !equalScalar(x, y);
}
});
const createUnequalNumber = exports.createUnequalNumber = (0, _factory.factory)(name, ['typed', 'equalScalar'], _ref2 => {
let {
typed,
equalScalar
} = _ref2;
return typed(name, {
'any, any': function (x, y) {
// strict equality for null and undefined?
if (x === null) {
return y !== null;
}
if (y === null) {
return x !== null;
}
if (x === undefined) {
return y !== undefined;
}
if (y === undefined) {
return x !== undefined;
}
return !equalScalar(x, y);
}
});
});