feat:node-modules
This commit is contained in:
30
node_modules/mathjs/lib/esm/function/utils/clone.js
generated
vendored
Normal file
30
node_modules/mathjs/lib/esm/function/utils/clone.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import { clone as objectClone } from '../../utils/object.js';
|
||||
import { factory } from '../../utils/factory.js';
|
||||
var name = 'clone';
|
||||
var dependencies = ['typed'];
|
||||
export var createClone = /* #__PURE__ */factory(name, dependencies, _ref => {
|
||||
var {
|
||||
typed
|
||||
} = _ref;
|
||||
/**
|
||||
* Clone an object. Will make a deep copy of the data.
|
||||
*
|
||||
* Syntax:
|
||||
*
|
||||
* math.clone(x)
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* math.clone(3.5) // returns number 3.5
|
||||
* math.clone(math.complex('2-4i')) // returns Complex 2 - 4i
|
||||
* math.clone(math.unit(45, 'deg')) // returns Unit 45 deg
|
||||
* math.clone([[1, 2], [3, 4]]) // returns Array [[1, 2], [3, 4]]
|
||||
* math.clone("hello world") // returns string "hello world"
|
||||
*
|
||||
* @param {*} x Object to be cloned
|
||||
* @return {*} A clone of object x
|
||||
*/
|
||||
return typed(name, {
|
||||
any: objectClone
|
||||
});
|
||||
});
|
||||
50
node_modules/mathjs/lib/esm/function/utils/hasNumericValue.js
generated
vendored
Normal file
50
node_modules/mathjs/lib/esm/function/utils/hasNumericValue.js
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
import { factory } from '../../utils/factory.js';
|
||||
var name = 'hasNumericValue';
|
||||
var dependencies = ['typed', 'isNumeric'];
|
||||
export var createHasNumericValue = /* #__PURE__ */factory(name, dependencies, _ref => {
|
||||
var {
|
||||
typed,
|
||||
isNumeric
|
||||
} = _ref;
|
||||
/**
|
||||
* Test whether a value is an numeric value.
|
||||
*
|
||||
* In case of a string, true is returned if the string contains a numeric value.
|
||||
*
|
||||
* Syntax:
|
||||
*
|
||||
* math.hasNumericValue(x)
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* math.hasNumericValue(2) // returns true
|
||||
* math.hasNumericValue('2') // returns true
|
||||
* math.isNumeric('2') // returns false
|
||||
* math.hasNumericValue(0) // returns true
|
||||
* math.hasNumericValue(math.bignumber('500')) // returns true
|
||||
* math.hasNumericValue(math.bigint('42')) // returns true
|
||||
* math.hasNumericValue(42n) // returns true
|
||||
* math.hasNumericValue(math.fraction(4)) // returns true
|
||||
* math.hasNumericValue(math.complex('2-4i')) // returns false
|
||||
* math.hasNumericValue(false) // returns true
|
||||
* math.hasNumericValue([2.3, 'foo', false]) // returns [true, false, true]
|
||||
*
|
||||
* See also:
|
||||
*
|
||||
* isZero, isPositive, isNegative, isInteger, isNumeric
|
||||
*
|
||||
* @param {*} x Value to be tested
|
||||
* @return {boolean} Returns true when `x` is a `number`, `BigNumber`,
|
||||
* `Fraction`, `Boolean`, or a `String` containing number. Returns false for other types.
|
||||
* Throws an error in case of unknown types.
|
||||
*/
|
||||
return typed(name, {
|
||||
boolean: () => true,
|
||||
string: function string(x) {
|
||||
return x.trim().length > 0 && !isNaN(Number(x));
|
||||
},
|
||||
any: function any(x) {
|
||||
return isNumeric(x);
|
||||
}
|
||||
});
|
||||
});
|
||||
54
node_modules/mathjs/lib/esm/function/utils/isInteger.js
generated
vendored
Normal file
54
node_modules/mathjs/lib/esm/function/utils/isInteger.js
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
import { deepMap } from '../../utils/collection.js';
|
||||
import { isInteger as isIntegerNumber } from '../../utils/number.js';
|
||||
import { factory } from '../../utils/factory.js';
|
||||
var name = 'isInteger';
|
||||
var dependencies = ['typed'];
|
||||
export var createIsInteger = /* #__PURE__ */factory(name, dependencies, _ref => {
|
||||
var {
|
||||
typed
|
||||
} = _ref;
|
||||
/**
|
||||
* Test whether a value is an integer number.
|
||||
* The function supports `number`, `BigNumber`, and `Fraction`.
|
||||
*
|
||||
* The function is evaluated element-wise in case of Array or Matrix input.
|
||||
*
|
||||
* Syntax:
|
||||
*
|
||||
* math.isInteger(x)
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* math.isInteger(2) // returns true
|
||||
* math.isInteger(0) // returns true
|
||||
* math.isInteger(0.5) // returns false
|
||||
* math.isInteger(math.bignumber(500)) // returns true
|
||||
* math.isInteger(math.fraction(4)) // returns true
|
||||
* math.isInteger('3') // returns true
|
||||
* math.isInteger([3, 0.5, -2]) // returns [true, false, true]
|
||||
* math.isInteger(math.complex('2-4i')) // throws an error
|
||||
*
|
||||
* See also:
|
||||
*
|
||||
* isNumeric, isPositive, isNegative, isZero
|
||||
*
|
||||
* @param {number | BigNumber | bigint | Fraction | Array | Matrix} x Value to be tested
|
||||
* @return {boolean} Returns true when `x` contains a numeric, integer value.
|
||||
* Throws an error in case of an unknown data type.
|
||||
*/
|
||||
return typed(name, {
|
||||
number: isIntegerNumber,
|
||||
// TODO: what to do with isInteger(add(0.1, 0.2)) ?
|
||||
|
||||
BigNumber: function BigNumber(x) {
|
||||
return x.isInt();
|
||||
},
|
||||
bigint: function bigint(x) {
|
||||
return true;
|
||||
},
|
||||
Fraction: function Fraction(x) {
|
||||
return x.d === 1 && isFinite(x.n);
|
||||
},
|
||||
'Array | Matrix': typed.referToSelf(self => x => deepMap(x, self))
|
||||
});
|
||||
});
|
||||
58
node_modules/mathjs/lib/esm/function/utils/isNaN.js
generated
vendored
Normal file
58
node_modules/mathjs/lib/esm/function/utils/isNaN.js
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
import { deepMap } from '../../utils/collection.js';
|
||||
import { factory } from '../../utils/factory.js';
|
||||
import { isNaNNumber } from '../../plain/number/index.js';
|
||||
var name = 'isNaN';
|
||||
var dependencies = ['typed'];
|
||||
export var createIsNaN = /* #__PURE__ */factory(name, dependencies, _ref => {
|
||||
var {
|
||||
typed
|
||||
} = _ref;
|
||||
/**
|
||||
* Test whether a value is NaN (not a number).
|
||||
* The function supports types `number`, `BigNumber`, `Fraction`, `Unit` and `Complex`.
|
||||
*
|
||||
* The function is evaluated element-wise in case of Array or Matrix input.
|
||||
*
|
||||
* Syntax:
|
||||
*
|
||||
* math.isNaN(x)
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* math.isNaN(3) // returns false
|
||||
* math.isNaN(NaN) // returns true
|
||||
* math.isNaN(0) // returns false
|
||||
* math.isNaN(math.bignumber(NaN)) // returns true
|
||||
* math.isNaN(math.bignumber(0)) // returns false
|
||||
* math.isNaN(math.fraction(-2, 5)) // returns false
|
||||
* math.isNaN('-2') // returns false
|
||||
* math.isNaN([2, 0, -3, NaN]) // returns [false, false, false, true]
|
||||
*
|
||||
* See also:
|
||||
*
|
||||
* isNumeric, isNegative, isPositive, isZero, isInteger
|
||||
*
|
||||
* @param {number | BigNumber | bigint | Fraction | Unit | Array | Matrix} x Value to be tested
|
||||
* @return {boolean} Returns true when `x` is NaN.
|
||||
* Throws an error in case of an unknown data type.
|
||||
*/
|
||||
return typed(name, {
|
||||
number: isNaNNumber,
|
||||
BigNumber: function BigNumber(x) {
|
||||
return x.isNaN();
|
||||
},
|
||||
bigint: function bigint(x) {
|
||||
return false;
|
||||
},
|
||||
Fraction: function Fraction(x) {
|
||||
return false;
|
||||
},
|
||||
Complex: function Complex(x) {
|
||||
return x.isNaN();
|
||||
},
|
||||
Unit: function Unit(x) {
|
||||
return Number.isNaN(x.value);
|
||||
},
|
||||
'Array | Matrix': typed.referToSelf(self => x => deepMap(x, self))
|
||||
});
|
||||
});
|
||||
52
node_modules/mathjs/lib/esm/function/utils/isNegative.js
generated
vendored
Normal file
52
node_modules/mathjs/lib/esm/function/utils/isNegative.js
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
import { deepMap } from '../../utils/collection.js';
|
||||
import { factory } from '../../utils/factory.js';
|
||||
import { isNegativeNumber } from '../../plain/number/index.js';
|
||||
import { nearlyEqual as bigNearlyEqual } from '../../utils/bignumber/nearlyEqual.js';
|
||||
import { nearlyEqual } from '../../utils/number.js';
|
||||
var name = 'isNegative';
|
||||
var dependencies = ['typed', 'config'];
|
||||
export var createIsNegative = /* #__PURE__ */factory(name, dependencies, _ref => {
|
||||
var {
|
||||
typed,
|
||||
config
|
||||
} = _ref;
|
||||
/**
|
||||
* Test whether a value is negative: smaller than zero.
|
||||
* The function supports types `number`, `BigNumber`, `Fraction`, and `Unit`.
|
||||
*
|
||||
* The function is evaluated element-wise in case of Array or Matrix input.
|
||||
*
|
||||
* Syntax:
|
||||
*
|
||||
* math.isNegative(x)
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* math.isNegative(3) // returns false
|
||||
* math.isNegative(-2) // returns true
|
||||
* math.isNegative(0) // returns false
|
||||
* math.isNegative(-0) // returns false
|
||||
* math.isNegative(math.bignumber(2)) // returns false
|
||||
* math.isNegative(math.fraction(-2, 5)) // returns true
|
||||
* math.isNegative('-2') // returns true
|
||||
* math.isNegative([2, 0, -3]) // returns [false, false, true]
|
||||
*
|
||||
* See also:
|
||||
*
|
||||
* isNumeric, isPositive, isZero, isInteger
|
||||
*
|
||||
* @param {number | BigNumber | bigint | Fraction | Unit | Array | Matrix} x Value to be tested
|
||||
* @return {boolean} Returns true when `x` is larger than zero.
|
||||
* Throws an error in case of an unknown data type.
|
||||
*/
|
||||
return typed(name, {
|
||||
number: x => nearlyEqual(x, 0, config.relTol, config.absTol) ? false : isNegativeNumber(x),
|
||||
BigNumber: x => bigNearlyEqual(x, new x.constructor(0), config.relTol, config.absTol) ? false : x.isNeg() && !x.isZero() && !x.isNaN(),
|
||||
bigint: x => x < 0n,
|
||||
Fraction: x => x.s < 0,
|
||||
// It's enough to decide on the sign
|
||||
|
||||
Unit: typed.referToSelf(self => x => typed.find(self, x.valueType())(x.value)),
|
||||
'Array | Matrix': typed.referToSelf(self => x => deepMap(x, self))
|
||||
});
|
||||
});
|
||||
44
node_modules/mathjs/lib/esm/function/utils/isNumeric.js
generated
vendored
Normal file
44
node_modules/mathjs/lib/esm/function/utils/isNumeric.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
import { deepMap } from '../../utils/collection.js';
|
||||
import { factory } from '../../utils/factory.js';
|
||||
var name = 'isNumeric';
|
||||
var dependencies = ['typed'];
|
||||
export var createIsNumeric = /* #__PURE__ */factory(name, dependencies, _ref => {
|
||||
var {
|
||||
typed
|
||||
} = _ref;
|
||||
/**
|
||||
* Test whether a value is an numeric value.
|
||||
*
|
||||
* The function is evaluated element-wise in case of Array or Matrix input.
|
||||
*
|
||||
* Syntax:
|
||||
*
|
||||
* math.isNumeric(x)
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* math.isNumeric(2) // returns true
|
||||
* math.isNumeric('2') // returns false
|
||||
* math.hasNumericValue('2') // returns true
|
||||
* math.isNumeric(0) // returns true
|
||||
* math.isNumeric(math.bignumber('42')) // returns true
|
||||
* math.isNumeric(math.bigint('42')) // returns true
|
||||
* math.isNumeric(math.fraction(4)) // returns true
|
||||
* math.isNumeric(math.complex('2-4i')) // returns false
|
||||
* math.isNumeric([2.3, 'foo', false]) // returns [true, false, true]
|
||||
*
|
||||
* See also:
|
||||
*
|
||||
* isZero, isPositive, isNegative, isInteger, hasNumericValue
|
||||
*
|
||||
* @param {*} x Value to be tested
|
||||
* @return {boolean} Returns true when `x` is a `number`, `BigNumber`,
|
||||
* `Fraction`, or `boolean`. Returns false for other types.
|
||||
* Throws an error in case of unknown types.
|
||||
*/
|
||||
return typed(name, {
|
||||
'number | BigNumber | bigint | Fraction | boolean': () => true,
|
||||
'Complex | Unit | string | null | undefined | Node': () => false,
|
||||
'Array | Matrix': typed.referToSelf(self => x => deepMap(x, self))
|
||||
});
|
||||
});
|
||||
52
node_modules/mathjs/lib/esm/function/utils/isPositive.js
generated
vendored
Normal file
52
node_modules/mathjs/lib/esm/function/utils/isPositive.js
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
import { deepMap } from '../../utils/collection.js';
|
||||
import { factory } from '../../utils/factory.js';
|
||||
import { isPositiveNumber } from '../../plain/number/index.js';
|
||||
import { nearlyEqual as bigNearlyEqual } from '../../utils/bignumber/nearlyEqual.js';
|
||||
import { nearlyEqual } from '../../utils/number.js';
|
||||
var name = 'isPositive';
|
||||
var dependencies = ['typed', 'config'];
|
||||
export var createIsPositive = /* #__PURE__ */factory(name, dependencies, _ref => {
|
||||
var {
|
||||
typed,
|
||||
config
|
||||
} = _ref;
|
||||
/**
|
||||
* Test whether a value is positive: larger than zero.
|
||||
* The function supports types `number`, `BigNumber`, `Fraction`, and `Unit`.
|
||||
*
|
||||
* The function is evaluated element-wise in case of Array or Matrix input.
|
||||
*
|
||||
* Syntax:
|
||||
*
|
||||
* math.isPositive(x)
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* math.isPositive(3) // returns true
|
||||
* math.isPositive(-2) // returns false
|
||||
* math.isPositive(0) // returns false
|
||||
* math.isPositive(-0) // returns false
|
||||
* math.isPositive(0.5) // returns true
|
||||
* math.isPositive(math.bignumber(2)) // returns true
|
||||
* math.isPositive(math.fraction(-2, 5)) // returns false
|
||||
* math.isPositive(math.fraction(1, 3)) // returns true
|
||||
* math.isPositive('2') // returns true
|
||||
* math.isPositive([2, 0, -3]) // returns [true, false, false]
|
||||
*
|
||||
* See also:
|
||||
*
|
||||
* isNumeric, isZero, isNegative, isInteger
|
||||
*
|
||||
* @param {number | BigNumber | bigint | Fraction | Unit | Array | Matrix} x Value to be tested
|
||||
* @return {boolean} Returns true when `x` is larger than zero.
|
||||
* Throws an error in case of an unknown data type.
|
||||
*/
|
||||
return typed(name, {
|
||||
number: x => nearlyEqual(x, 0, config.relTol, config.absTol) ? false : isPositiveNumber(x),
|
||||
BigNumber: x => bigNearlyEqual(x, new x.constructor(0), config.relTol, config.absTol) ? false : !x.isNeg() && !x.isZero() && !x.isNaN(),
|
||||
bigint: x => x > 0n,
|
||||
Fraction: x => x.s > 0 && x.n > 0,
|
||||
Unit: typed.referToSelf(self => x => typed.find(self, x.valueType())(x.value)),
|
||||
'Array | Matrix': typed.referToSelf(self => x => deepMap(x, self))
|
||||
});
|
||||
});
|
||||
130
node_modules/mathjs/lib/esm/function/utils/isPrime.js
generated
vendored
Normal file
130
node_modules/mathjs/lib/esm/function/utils/isPrime.js
generated
vendored
Normal file
@@ -0,0 +1,130 @@
|
||||
import { deepMap } from '../../utils/collection.js';
|
||||
import { factory } from '../../utils/factory.js';
|
||||
var name = 'isPrime';
|
||||
var dependencies = ['typed'];
|
||||
export var createIsPrime = /* #__PURE__ */factory(name, dependencies, _ref => {
|
||||
var {
|
||||
typed
|
||||
} = _ref;
|
||||
/**
|
||||
* Test whether a value is prime: has no divisors other than itself and one.
|
||||
* The function supports type `number`, `bignumber`.
|
||||
*
|
||||
* The function is evaluated element-wise in case of Array or Matrix input.
|
||||
*
|
||||
* Syntax:
|
||||
*
|
||||
* math.isPrime(x)
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* math.isPrime(3) // returns true
|
||||
* math.isPrime(-2) // returns false
|
||||
* math.isPrime(0) // returns false
|
||||
* math.isPrime(-0) // returns false
|
||||
* math.isPrime(0.5) // returns false
|
||||
* math.isPrime('2') // returns true
|
||||
* math.isPrime([2, 17, 100]) // returns [true, true, false]
|
||||
*
|
||||
* See also:
|
||||
*
|
||||
* isNumeric, isZero, isNegative, isInteger
|
||||
*
|
||||
* @param {number | BigNumber | bigint | Array | Matrix} x Value to be tested
|
||||
* @return {boolean} Returns true when `x` is larger than zero.
|
||||
* Throws an error in case of an unknown data type.
|
||||
*/
|
||||
return typed(name, {
|
||||
number: function number(x) {
|
||||
if (x <= 3) {
|
||||
return x > 1;
|
||||
}
|
||||
if (x % 2 === 0 || x % 3 === 0) {
|
||||
return false;
|
||||
}
|
||||
for (var i = 5; i * i <= x; i += 6) {
|
||||
if (x % i === 0 || x % (i + 2) === 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
},
|
||||
bigint: function bigint(x) {
|
||||
if (x <= 3n) {
|
||||
return x > 1n;
|
||||
}
|
||||
if (x % 2n === 0n || x % 3n === 0n) {
|
||||
return false;
|
||||
}
|
||||
for (var i = 5n; i * i <= x; i += 6n) {
|
||||
if (x % i === 0n || x % (i + 2n) === 0n) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
},
|
||||
BigNumber: function BigNumber(n) {
|
||||
if (n.lte(3)) return n.gt(1);
|
||||
if (n.mod(2).eq(0) || n.mod(3).eq(0)) return false;
|
||||
if (n.lt(Math.pow(2, 32))) {
|
||||
var x = n.toNumber();
|
||||
for (var i = 5; i * i <= x; i += 6) {
|
||||
if (x % i === 0 || x % (i + 2) === 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function modPow(base, exponent, modulus) {
|
||||
// exponent can be huge, use non-recursive variant
|
||||
var accumulator = 1;
|
||||
while (!exponent.eq(0)) {
|
||||
if (exponent.mod(2).eq(0)) {
|
||||
exponent = exponent.div(2);
|
||||
base = base.mul(base).mod(modulus);
|
||||
} else {
|
||||
exponent = exponent.sub(1);
|
||||
accumulator = base.mul(accumulator).mod(modulus);
|
||||
}
|
||||
}
|
||||
return accumulator;
|
||||
}
|
||||
|
||||
// https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test#Deterministic_variants
|
||||
var Decimal = n.constructor.clone({
|
||||
precision: n.toFixed(0).length * 2
|
||||
});
|
||||
n = new Decimal(n);
|
||||
var r = 0;
|
||||
var d = n.sub(1);
|
||||
while (d.mod(2).eq(0)) {
|
||||
d = d.div(2);
|
||||
r += 1;
|
||||
}
|
||||
var bases = null;
|
||||
// https://en.wikipedia.org/wiki/Miller–Rabin_primality_test#Testing_against_small_sets_of_bases
|
||||
if (n.lt('3317044064679887385961981')) {
|
||||
bases = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41].filter(x => x < n);
|
||||
} else {
|
||||
var max = Math.min(n.toNumber() - 2, Math.floor(2 * Math.pow(n.toFixed(0).length * Math.log(10), 2)));
|
||||
bases = [];
|
||||
for (var _i = 2; _i <= max; _i += 1) {
|
||||
bases.push(max);
|
||||
}
|
||||
}
|
||||
for (var _i2 = 0; _i2 < bases.length; _i2 += 1) {
|
||||
var a = bases[_i2];
|
||||
var adn = modPow(n.sub(n).add(a), d, n);
|
||||
if (!adn.eq(1)) {
|
||||
for (var _i3 = 0, _x = adn; !_x.eq(n.sub(1)); _i3 += 1, _x = _x.mul(_x).mod(n)) {
|
||||
if (_i3 === r - 1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
},
|
||||
'Array | Matrix': typed.referToSelf(self => x => deepMap(x, self))
|
||||
});
|
||||
});
|
||||
49
node_modules/mathjs/lib/esm/function/utils/isZero.js
generated
vendored
Normal file
49
node_modules/mathjs/lib/esm/function/utils/isZero.js
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
import { deepMap } from '../../utils/collection.js';
|
||||
import { factory } from '../../utils/factory.js';
|
||||
var name = 'isZero';
|
||||
var dependencies = ['typed', 'equalScalar'];
|
||||
export var createIsZero = /* #__PURE__ */factory(name, dependencies, _ref => {
|
||||
var {
|
||||
typed,
|
||||
equalScalar
|
||||
} = _ref;
|
||||
/**
|
||||
* Test whether a value is zero.
|
||||
* The function can check for zero for types `number`, `BigNumber`, `Fraction`,
|
||||
* `Complex`, and `Unit`.
|
||||
*
|
||||
* The function is evaluated element-wise in case of Array or Matrix input.
|
||||
*
|
||||
* Syntax:
|
||||
*
|
||||
* math.isZero(x)
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* math.isZero(0) // returns true
|
||||
* math.isZero(2) // returns false
|
||||
* math.isZero(0.5) // returns false
|
||||
* math.isZero(math.bignumber(0)) // returns true
|
||||
* math.isZero(math.fraction(0)) // returns true
|
||||
* math.isZero(math.fraction(1,3)) // returns false
|
||||
* math.isZero(math.complex('2 - 4i')) // returns false
|
||||
* math.isZero(math.complex('0i')) // returns true
|
||||
* math.isZero('0') // returns true
|
||||
* math.isZero('2') // returns false
|
||||
* math.isZero([2, 0, -3]) // returns [false, true, false]
|
||||
*
|
||||
* See also:
|
||||
*
|
||||
* isNumeric, isPositive, isNegative, isInteger
|
||||
*
|
||||
* @param {number | BigNumber | bigint | Complex | Fraction | Unit | Array | Matrix} x Value to be tested
|
||||
* @return {boolean} Returns true when `x` is zero.
|
||||
* Throws an error in case of an unknown data type.
|
||||
*/
|
||||
return typed(name, {
|
||||
'number | BigNumber | Complex | Fraction': x => equalScalar(x, 0),
|
||||
bigint: x => x === 0n,
|
||||
Unit: typed.referToSelf(self => x => typed.find(self, x.valueType())(x.value)),
|
||||
'Array | Matrix': typed.referToSelf(self => x => deepMap(x, self))
|
||||
});
|
||||
});
|
||||
75
node_modules/mathjs/lib/esm/function/utils/numeric.js
generated
vendored
Normal file
75
node_modules/mathjs/lib/esm/function/utils/numeric.js
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
import { typeOf } from '../../utils/is.js';
|
||||
import { factory } from '../../utils/factory.js';
|
||||
import { noBignumber, noFraction } from '../../utils/noop.js';
|
||||
var name = 'numeric';
|
||||
var dependencies = ['number', '?bignumber', '?fraction'];
|
||||
export var createNumeric = /* #__PURE__ */factory(name, dependencies, _ref => {
|
||||
var {
|
||||
number: _number,
|
||||
bignumber,
|
||||
fraction
|
||||
} = _ref;
|
||||
var validInputTypes = {
|
||||
string: true,
|
||||
number: true,
|
||||
BigNumber: true,
|
||||
Fraction: true
|
||||
};
|
||||
|
||||
// Load the conversion functions for each output type
|
||||
var validOutputTypes = {
|
||||
number: x => _number(x),
|
||||
BigNumber: bignumber ? x => bignumber(x) : noBignumber,
|
||||
bigint: x => BigInt(x),
|
||||
Fraction: fraction ? x => fraction(x) : noFraction
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert a numeric input to a specific numeric type: number, BigNumber, bigint, or Fraction.
|
||||
*
|
||||
* Syntax:
|
||||
*
|
||||
* math.numeric(x)
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* math.numeric('4') // returns 4
|
||||
* math.numeric('4', 'number') // returns 4
|
||||
* math.numeric('4', 'bigint') // returns 4n
|
||||
* math.numeric('4', 'BigNumber') // returns BigNumber 4
|
||||
* math.numeric('4', 'Fraction') // returns Fraction 4
|
||||
* math.numeric(4, 'Fraction') // returns Fraction 4
|
||||
* math.numeric(math.fraction(2, 5), 'number') // returns 0.4
|
||||
*
|
||||
* See also:
|
||||
*
|
||||
* number, fraction, bignumber, bigint, string, format
|
||||
*
|
||||
* @param {string | number | BigNumber | bigint | Fraction } value
|
||||
* A numeric value or a string containing a numeric value
|
||||
* @param {string} outputType
|
||||
* Desired numeric output type.
|
||||
* Available values: 'number', 'BigNumber', or 'Fraction'
|
||||
* @return {number | BigNumber | bigint | Fraction}
|
||||
* Returns an instance of the numeric in the requested type
|
||||
*/
|
||||
return function numeric(value) {
|
||||
var outputType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'number';
|
||||
var check = arguments.length > 2 ? arguments[2] : undefined;
|
||||
if (check !== undefined) {
|
||||
throw new SyntaxError('numeric() takes one or two arguments');
|
||||
}
|
||||
var inputType = typeOf(value);
|
||||
if (!(inputType in validInputTypes)) {
|
||||
throw new TypeError('Cannot convert ' + value + ' of type "' + inputType + '"; valid input types are ' + Object.keys(validInputTypes).join(', '));
|
||||
}
|
||||
if (!(outputType in validOutputTypes)) {
|
||||
throw new TypeError('Cannot convert ' + value + ' to type "' + outputType + '"; valid output types are ' + Object.keys(validOutputTypes).join(', '));
|
||||
}
|
||||
if (outputType === inputType) {
|
||||
return value;
|
||||
} else {
|
||||
return validOutputTypes[outputType](value);
|
||||
}
|
||||
};
|
||||
});
|
||||
65
node_modules/mathjs/lib/esm/function/utils/typeOf.js
generated
vendored
Normal file
65
node_modules/mathjs/lib/esm/function/utils/typeOf.js
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
import { factory } from '../../utils/factory.js';
|
||||
import { typeOf as _typeOf } from '../../utils/is.js';
|
||||
var name = 'typeOf';
|
||||
var dependencies = ['typed'];
|
||||
export var createTypeOf = /* #__PURE__ */factory(name, dependencies, _ref => {
|
||||
var {
|
||||
typed
|
||||
} = _ref;
|
||||
/**
|
||||
* Determine the type of an entity.
|
||||
*
|
||||
* Syntax:
|
||||
*
|
||||
* math.typeOf(x)
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* // This list is intended to include all relevant types, for testing
|
||||
* // purposes:
|
||||
* math.typeOf(3.5) // returns 'number'
|
||||
* math.typeOf(42n) // returns 'bigint'
|
||||
* math.typeOf(math.complex('2-4i')) // returns 'Complex'
|
||||
* math.typeOf(math.unit('45 deg')) // returns 'Unit'
|
||||
* math.typeOf('hello world') // returns 'string'
|
||||
* math.typeOf(null) // returns 'null'
|
||||
* math.typeOf(true) // returns 'boolean'
|
||||
* math.typeOf([1, 2, 3]) // returns 'Array'
|
||||
* math.typeOf(new Date()) // returns 'Date'
|
||||
* math.typeOf(function () {}) // returns 'function'
|
||||
* math.typeOf({a: 2, b: 3}) // returns 'Object'
|
||||
* math.typeOf(/a regexp/) // returns 'RegExp'
|
||||
* math.typeOf(undefined) // returns 'undefined'
|
||||
* math.typeOf(math.bignumber('23e99')) // returns 'BigNumber'
|
||||
* math.typeOf(math.chain(2)) // returns 'Chain'
|
||||
* math.typeOf(math.fraction(1, 3)) // returns 'Fraction'
|
||||
* math.typeOf(math.help('sqrt')) // returns 'Help'
|
||||
* math.typeOf(math.index(1, 3)) // returns 'Index'
|
||||
* math.typeOf(math.matrix([[1],[3]])) // returns 'DenseMatrix'
|
||||
* math.typeOf(math.matrix([],'sparse')) // returns 'SparseMatrix'
|
||||
* math.typeOf(new math.Range(0, 10)) // returns 'Range'
|
||||
* math.typeOf(math.evaluate('a=2\na')) // returns 'ResultSet'
|
||||
* math.typeOf(math.parse('A[2]')) // returns 'AccessorNode'
|
||||
* math.typeOf(math.parse('[1,2,3]')) // returns 'ArrayNode'
|
||||
* math.typeOf(math.parse('x=2')) // returns 'AssignmentNode'
|
||||
* math.typeOf(math.parse('a=2; b=3')) // returns 'BlockNode'
|
||||
* math.typeOf(math.parse('x<0?-1:1')) // returns 'ConditionalNode'
|
||||
* math.typeOf(math.parse('2.3')) // returns 'ConstantNode'
|
||||
* math.typeOf(math.parse('f(x)=x^2')) // returns 'FunctionAssignmentNode'
|
||||
* math.typeOf(math.parse('sqrt(4)')) // returns 'FunctionNode'
|
||||
* math.typeOf(math.parse('A[2]').index) // returns 'IndexNode'
|
||||
* math.typeOf(math.parse('{a:2}')) // returns 'ObjectNode'
|
||||
* math.typeOf(math.parse('(2+3)')) // returns 'ParenthesisNode'
|
||||
* math.typeOf(math.parse('1:10')) // returns 'RangeNode'
|
||||
* math.typeOf(math.parse('a<b<c')) // returns 'RelationalNode'
|
||||
* math.typeOf(math.parse('x')) // returns 'SymbolNode'
|
||||
*
|
||||
* @param {*} x The variable for which to test the type.
|
||||
* @return {string} Returns the name of the type. Primitive types are lower case,
|
||||
* non-primitive types are upper-camel-case.
|
||||
* For example 'number', 'string', 'Array', 'Date'.
|
||||
*/
|
||||
return typed(name, {
|
||||
any: _typeOf
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user