mathjs 10.4.2 → 10.4.3
Sign up to get free protection for your applications and to get access to all the features.
- package/HISTORY.md +9 -0
- package/docs/expressions/syntax.md +7 -3
- package/docs/reference/functions/stirlingS2.md +5 -1
- package/lib/browser/math.js +3 -3
- package/lib/browser/math.js.map +1 -1
- package/lib/cjs/entry/dependenciesAny/dependenciesStirlingS2.generated.js +6 -0
- package/lib/cjs/entry/dependenciesNumber/dependenciesStirlingS2.generated.js +3 -0
- package/lib/cjs/entry/pureFunctionsAny.generated.js +2 -0
- package/lib/cjs/entry/pureFunctionsNumber.generated.js +1 -0
- package/lib/cjs/factoriesNumber.js +12 -2
- package/lib/cjs/function/combinatorics/stirlingS2.js +42 -12
- package/lib/cjs/header.js +2 -2
- package/lib/cjs/plain/number/arithmetic.js +8 -4
- package/lib/cjs/version.js +1 -1
- package/lib/esm/entry/dependenciesAny/dependenciesStirlingS2.generated.js +4 -0
- package/lib/esm/entry/dependenciesNumber/dependenciesStirlingS2.generated.js +2 -0
- package/lib/esm/entry/pureFunctionsAny.generated.js +2 -0
- package/lib/esm/entry/pureFunctionsNumber.generated.js +1 -0
- package/lib/esm/factoriesNumber.js +14 -2
- package/lib/esm/function/combinatorics/stirlingS2.js +41 -12
- package/lib/esm/plain/number/arithmetic.js +7 -3
- package/lib/esm/version.js +1 -1
- package/package.json +1 -1
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.stirlingS2Dependencies = void 0;
|
7
7
|
|
8
|
+
var _dependenciesBignumberGenerated = require("./dependenciesBignumber.generated.js");
|
9
|
+
|
8
10
|
var _dependenciesAddScalarGenerated = require("./dependenciesAddScalar.generated.js");
|
9
11
|
|
10
12
|
var _dependenciesCombinationsGenerated = require("./dependenciesCombinations.generated.js");
|
@@ -21,6 +23,8 @@ var _dependenciesLargerGenerated = require("./dependenciesLarger.generated.js");
|
|
21
23
|
|
22
24
|
var _dependenciesMultiplyScalarGenerated = require("./dependenciesMultiplyScalar.generated.js");
|
23
25
|
|
26
|
+
var _dependenciesNumberGenerated = require("./dependenciesNumber.generated.js");
|
27
|
+
|
24
28
|
var _dependenciesPowGenerated = require("./dependenciesPow.generated.js");
|
25
29
|
|
26
30
|
var _dependenciesSubtractGenerated = require("./dependenciesSubtract.generated.js");
|
@@ -34,6 +38,7 @@ var _factoriesAny = require("../../factoriesAny.js");
|
|
34
38
|
* DON'T MAKE CHANGES HERE
|
35
39
|
*/
|
36
40
|
var stirlingS2Dependencies = {
|
41
|
+
bignumberDependencies: _dependenciesBignumberGenerated.bignumberDependencies,
|
37
42
|
addScalarDependencies: _dependenciesAddScalarGenerated.addScalarDependencies,
|
38
43
|
combinationsDependencies: _dependenciesCombinationsGenerated.combinationsDependencies,
|
39
44
|
divideScalarDependencies: _dependenciesDivideScalarGenerated.divideScalarDependencies,
|
@@ -42,6 +47,7 @@ var stirlingS2Dependencies = {
|
|
42
47
|
isNegativeDependencies: _dependenciesIsNegativeGenerated.isNegativeDependencies,
|
43
48
|
largerDependencies: _dependenciesLargerGenerated.largerDependencies,
|
44
49
|
multiplyScalarDependencies: _dependenciesMultiplyScalarGenerated.multiplyScalarDependencies,
|
50
|
+
numberDependencies: _dependenciesNumberGenerated.numberDependencies,
|
45
51
|
powDependencies: _dependenciesPowGenerated.powDependencies,
|
46
52
|
subtractDependencies: _dependenciesSubtractGenerated.subtractDependencies,
|
47
53
|
typedDependencies: _dependenciesTypedGenerated.typedDependencies,
|
@@ -21,6 +21,8 @@ var _dependenciesLargerGenerated = require("./dependenciesLarger.generated.js");
|
|
21
21
|
|
22
22
|
var _dependenciesMultiplyScalarGenerated = require("./dependenciesMultiplyScalar.generated.js");
|
23
23
|
|
24
|
+
var _dependenciesNumberGenerated = require("./dependenciesNumber.generated.js");
|
25
|
+
|
24
26
|
var _dependenciesPowGenerated = require("./dependenciesPow.generated.js");
|
25
27
|
|
26
28
|
var _dependenciesSubtractGenerated = require("./dependenciesSubtract.generated.js");
|
@@ -42,6 +44,7 @@ var stirlingS2Dependencies = {
|
|
42
44
|
isNegativeDependencies: _dependenciesIsNegativeGenerated.isNegativeDependencies,
|
43
45
|
largerDependencies: _dependenciesLargerGenerated.largerDependencies,
|
44
46
|
multiplyScalarDependencies: _dependenciesMultiplyScalarGenerated.multiplyScalarDependencies,
|
47
|
+
numberDependencies: _dependenciesNumberGenerated.numberDependencies,
|
45
48
|
powDependencies: _dependenciesPowGenerated.powDependencies,
|
46
49
|
subtractDependencies: _dependenciesSubtractGenerated.subtractDependencies,
|
47
50
|
typedDependencies: _dependenciesTypedGenerated.typedDependencies,
|
@@ -1619,6 +1619,7 @@ var speedOfLight = /* #__PURE__ */(0, _factoriesAny.createSpeedOfLight)({
|
|
1619
1619
|
});
|
1620
1620
|
exports.speedOfLight = speedOfLight;
|
1621
1621
|
var stirlingS2 = /* #__PURE__ */(0, _factoriesAny.createStirlingS2)({
|
1622
|
+
bignumber: bignumber,
|
1622
1623
|
addScalar: addScalar,
|
1623
1624
|
combinations: combinations,
|
1624
1625
|
divideScalar: divideScalar,
|
@@ -1627,6 +1628,7 @@ var stirlingS2 = /* #__PURE__ */(0, _factoriesAny.createStirlingS2)({
|
|
1627
1628
|
isNegative: isNegative,
|
1628
1629
|
larger: larger,
|
1629
1630
|
multiplyScalar: multiplyScalar,
|
1631
|
+
number: number,
|
1630
1632
|
pow: pow,
|
1631
1633
|
subtract: subtract,
|
1632
1634
|
typed: typed
|
@@ -1040,7 +1040,7 @@ var createDivideScalar = /* #__PURE__ */createNumberFactory('divideScalar', _ind
|
|
1040
1040
|
exports.createDivideScalar = createDivideScalar;
|
1041
1041
|
var createPow = /* #__PURE__ */createNumberFactory('pow', _index.powNumber);
|
1042
1042
|
exports.createPow = createPow;
|
1043
|
-
var createLog = /* #__PURE__ */
|
1043
|
+
var createLog = /* #__PURE__ */createNumberOptionalSecondArgFactory('log', _index.logNumber);
|
1044
1044
|
exports.createLog = createLog;
|
1045
1045
|
var createLog1p = /* #__PURE__ */createNumberFactory('log1p', _index.log1pNumber);
|
1046
1046
|
exports.createLog1p = createLog1p;
|
@@ -1166,10 +1166,20 @@ exports.createIsZero = createIsZero;
|
|
1166
1166
|
var createIsNaN = /* #__PURE__ */createNumberFactory('isNaN', _index.isNaNNumber);
|
1167
1167
|
exports.createIsNaN = createIsNaN;
|
1168
1168
|
|
1169
|
-
// helper
|
1169
|
+
// helper functions to create a factory function for a function which only needs typed-function
|
1170
1170
|
function createNumberFactory(name, fn) {
|
1171
1171
|
return (0, _factory.factory)(name, ['typed'], function (_ref) {
|
1172
1172
|
var typed = _ref.typed;
|
1173
1173
|
return typed(fn);
|
1174
1174
|
});
|
1175
|
+
}
|
1176
|
+
|
1177
|
+
function createNumberOptionalSecondArgFactory(name, fn) {
|
1178
|
+
return (0, _factory.factory)(name, ['typed'], function (_ref2) {
|
1179
|
+
var typed = _ref2.typed;
|
1180
|
+
return typed({
|
1181
|
+
number: fn,
|
1182
|
+
'number,number': fn
|
1183
|
+
});
|
1184
|
+
});
|
1175
1185
|
}
|
@@ -7,8 +7,10 @@ exports.createStirlingS2 = void 0;
|
|
7
7
|
|
8
8
|
var _factory = require("../../utils/factory.js");
|
9
9
|
|
10
|
+
var _is = require("../../utils/is.js");
|
11
|
+
|
10
12
|
var name = 'stirlingS2';
|
11
|
-
var dependencies = ['typed', 'addScalar', 'subtract', 'multiplyScalar', 'divideScalar', 'pow', 'factorial', 'combinations', 'isNegative', 'isInteger', 'larger'];
|
13
|
+
var dependencies = ['typed', 'addScalar', 'subtract', 'multiplyScalar', 'divideScalar', 'pow', 'factorial', 'combinations', 'isNegative', 'isInteger', 'number', '?bignumber', 'larger'];
|
12
14
|
var createStirlingS2 = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
|
13
15
|
var typed = _ref.typed,
|
14
16
|
addScalar = _ref.addScalar,
|
@@ -20,15 +22,22 @@ var createStirlingS2 = /* #__PURE__ */(0, _factory.factory)(name, dependencies,
|
|
20
22
|
combinations = _ref.combinations,
|
21
23
|
isNegative = _ref.isNegative,
|
22
24
|
isInteger = _ref.isInteger,
|
25
|
+
number = _ref.number,
|
26
|
+
bignumber = _ref.bignumber,
|
23
27
|
larger = _ref.larger;
|
24
|
-
|
28
|
+
var smallCache = [];
|
29
|
+
var bigCache = [];
|
25
30
|
/**
|
26
31
|
* The Stirling numbers of the second kind, counts the number of ways to partition
|
27
32
|
* a set of n labelled objects into k nonempty unlabelled subsets.
|
28
33
|
* stirlingS2 only takes integer arguments.
|
29
34
|
* The following condition must be enforced: k <= n.
|
30
35
|
*
|
31
|
-
* If n = k or k = 1, then s(n,k) = 1
|
36
|
+
* If n = k or k = 1 <= n, then s(n,k) = 1
|
37
|
+
* If k = 0 < n, then s(n,k) = 0
|
38
|
+
*
|
39
|
+
* Note that if either n or k is supplied as a BigNumber, the result will be
|
40
|
+
* as well.
|
32
41
|
*
|
33
42
|
* Syntax:
|
34
43
|
*
|
@@ -46,26 +55,47 @@ var createStirlingS2 = /* #__PURE__ */(0, _factory.factory)(name, dependencies,
|
|
46
55
|
* @param {Number | BigNumber} k Number of objects in the subset
|
47
56
|
* @return {Number | BigNumber} S(n,k)
|
48
57
|
*/
|
58
|
+
|
49
59
|
return typed(name, {
|
50
60
|
'number | BigNumber, number | BigNumber': function numberBigNumberNumberBigNumber(n, k) {
|
51
61
|
if (!isInteger(n) || isNegative(n) || !isInteger(k) || isNegative(k)) {
|
52
62
|
throw new TypeError('Non-negative integer value expected in function stirlingS2');
|
53
63
|
} else if (larger(k, n)) {
|
54
64
|
throw new TypeError('k must be less than or equal to n in function stirlingS2');
|
55
|
-
}
|
65
|
+
}
|
66
|
+
|
67
|
+
var big = !((0, _is.isNumber)(n) && (0, _is.isNumber)(k));
|
68
|
+
var cache = big ? bigCache : smallCache;
|
69
|
+
var make = big ? bignumber : number;
|
70
|
+
var nn = number(n);
|
71
|
+
var nk = number(k);
|
72
|
+
/* See if we already have the value: */
|
73
|
+
|
74
|
+
if (cache[nn] && cache[nn].length > nk) {
|
75
|
+
return cache[nn][nk];
|
76
|
+
}
|
77
|
+
/* Fill the cache */
|
78
|
+
|
56
79
|
|
80
|
+
for (var m = 0; m <= nn; ++m) {
|
81
|
+
if (!cache[m]) {
|
82
|
+
cache[m] = [m === 0 ? make(1) : make(0)];
|
83
|
+
}
|
57
84
|
|
58
|
-
|
59
|
-
|
85
|
+
if (m === 0) continue;
|
86
|
+
var row = cache[m];
|
87
|
+
var prev = cache[m - 1];
|
60
88
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
89
|
+
for (var i = row.length; i <= m && i <= nk; ++i) {
|
90
|
+
if (i === m) {
|
91
|
+
row[i] = 1;
|
92
|
+
} else {
|
93
|
+
row[i] = addScalar(multiplyScalar(make(i), prev[i]), prev[i - 1]);
|
94
|
+
}
|
95
|
+
}
|
66
96
|
}
|
67
97
|
|
68
|
-
return
|
98
|
+
return cache[nn][nk];
|
69
99
|
}
|
70
100
|
});
|
71
101
|
});
|
package/lib/cjs/header.js
CHANGED
@@ -6,8 +6,8 @@
|
|
6
6
|
* It features real and complex numbers, units, matrices, a large set of
|
7
7
|
* mathematical functions, and a flexible expression parser.
|
8
8
|
*
|
9
|
-
* @version 10.4.
|
10
|
-
* @date 2022-
|
9
|
+
* @version 10.4.3
|
10
|
+
* @date 2022-04-08
|
11
11
|
*
|
12
12
|
* @license
|
13
13
|
* Copyright (C) 2013-2022 Jos de Jong <wjosdejong@gmail.com>
|
@@ -178,22 +178,26 @@ function lcmNumber(a, b) {
|
|
178
178
|
|
179
179
|
lcmNumber.signature = n2;
|
180
180
|
/**
|
181
|
-
* Calculate the logarithm of a value.
|
181
|
+
* Calculate the logarithm of a value, optionally to a given base.
|
182
182
|
* @param {number} x
|
183
|
+
* @param {number | null | undefined} base
|
183
184
|
* @return {number}
|
184
185
|
*/
|
185
186
|
|
186
|
-
function logNumber(x) {
|
187
|
+
function logNumber(x, y) {
|
188
|
+
if (y) {
|
189
|
+
return Math.log(x) / Math.log(y);
|
190
|
+
}
|
191
|
+
|
187
192
|
return Math.log(x);
|
188
193
|
}
|
189
|
-
|
190
|
-
logNumber.signature = n1;
|
191
194
|
/**
|
192
195
|
* Calculate the 10-base logarithm of a number
|
193
196
|
* @param {number} x
|
194
197
|
* @return {number}
|
195
198
|
*/
|
196
199
|
|
200
|
+
|
197
201
|
function log10Number(x) {
|
198
202
|
return (0, _number.log10)(x);
|
199
203
|
}
|
package/lib/cjs/version.js
CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.version = void 0;
|
7
|
-
var version = '10.4.
|
7
|
+
var version = '10.4.3'; // Note: This file is automatically generated when building math.js.
|
8
8
|
// Changes made in this file will be overwritten.
|
9
9
|
|
10
10
|
exports.version = version;
|
@@ -2,6 +2,7 @@
|
|
2
2
|
* THIS FILE IS AUTO-GENERATED
|
3
3
|
* DON'T MAKE CHANGES HERE
|
4
4
|
*/
|
5
|
+
import { bignumberDependencies } from './dependenciesBignumber.generated.js';
|
5
6
|
import { addScalarDependencies } from './dependenciesAddScalar.generated.js';
|
6
7
|
import { combinationsDependencies } from './dependenciesCombinations.generated.js';
|
7
8
|
import { divideScalarDependencies } from './dependenciesDivideScalar.generated.js';
|
@@ -10,11 +11,13 @@ import { isIntegerDependencies } from './dependenciesIsInteger.generated.js';
|
|
10
11
|
import { isNegativeDependencies } from './dependenciesIsNegative.generated.js';
|
11
12
|
import { largerDependencies } from './dependenciesLarger.generated.js';
|
12
13
|
import { multiplyScalarDependencies } from './dependenciesMultiplyScalar.generated.js';
|
14
|
+
import { numberDependencies } from './dependenciesNumber.generated.js';
|
13
15
|
import { powDependencies } from './dependenciesPow.generated.js';
|
14
16
|
import { subtractDependencies } from './dependenciesSubtract.generated.js';
|
15
17
|
import { typedDependencies } from './dependenciesTyped.generated.js';
|
16
18
|
import { createStirlingS2 } from '../../factoriesAny.js';
|
17
19
|
export var stirlingS2Dependencies = {
|
20
|
+
bignumberDependencies,
|
18
21
|
addScalarDependencies,
|
19
22
|
combinationsDependencies,
|
20
23
|
divideScalarDependencies,
|
@@ -23,6 +26,7 @@ export var stirlingS2Dependencies = {
|
|
23
26
|
isNegativeDependencies,
|
24
27
|
largerDependencies,
|
25
28
|
multiplyScalarDependencies,
|
29
|
+
numberDependencies,
|
26
30
|
powDependencies,
|
27
31
|
subtractDependencies,
|
28
32
|
typedDependencies,
|
@@ -10,6 +10,7 @@ import { isIntegerDependencies } from './dependenciesIsInteger.generated.js';
|
|
10
10
|
import { isNegativeDependencies } from './dependenciesIsNegative.generated.js';
|
11
11
|
import { largerDependencies } from './dependenciesLarger.generated.js';
|
12
12
|
import { multiplyScalarDependencies } from './dependenciesMultiplyScalar.generated.js';
|
13
|
+
import { numberDependencies } from './dependenciesNumber.generated.js';
|
13
14
|
import { powDependencies } from './dependenciesPow.generated.js';
|
14
15
|
import { subtractDependencies } from './dependenciesSubtract.generated.js';
|
15
16
|
import { typedDependencies } from './dependenciesTyped.generated.js';
|
@@ -23,6 +24,7 @@ export var stirlingS2Dependencies = {
|
|
23
24
|
isNegativeDependencies,
|
24
25
|
largerDependencies,
|
25
26
|
multiplyScalarDependencies,
|
27
|
+
numberDependencies,
|
26
28
|
powDependencies,
|
27
29
|
subtractDependencies,
|
28
30
|
typedDependencies,
|
@@ -1339,6 +1339,7 @@ export var speedOfLight = /* #__PURE__ */createSpeedOfLight({
|
|
1339
1339
|
config
|
1340
1340
|
});
|
1341
1341
|
export var stirlingS2 = /* #__PURE__ */createStirlingS2({
|
1342
|
+
bignumber,
|
1342
1343
|
addScalar,
|
1343
1344
|
combinations,
|
1344
1345
|
divideScalar,
|
@@ -1347,6 +1348,7 @@ export var stirlingS2 = /* #__PURE__ */createStirlingS2({
|
|
1347
1348
|
isNegative,
|
1348
1349
|
larger,
|
1349
1350
|
multiplyScalar,
|
1351
|
+
number,
|
1350
1352
|
pow,
|
1351
1353
|
subtract,
|
1352
1354
|
typed
|
@@ -46,7 +46,7 @@ export var createXgcd = /* #__PURE__ */createNumberFactory('xgcd', xgcdNumber);
|
|
46
46
|
export var createDivideScalar = /* #__PURE__ */createNumberFactory('divideScalar', divideNumber);
|
47
47
|
export var createPow = /* #__PURE__ */createNumberFactory('pow', powNumber);
|
48
48
|
export { createRoundNumber as createRound } from './function/arithmetic/round.js';
|
49
|
-
export var createLog = /* #__PURE__ */
|
49
|
+
export var createLog = /* #__PURE__ */createNumberOptionalSecondArgFactory('log', logNumber);
|
50
50
|
export var createLog1p = /* #__PURE__ */createNumberFactory('log1p', log1pNumber);
|
51
51
|
export var createAdd = /* #__PURE__ */createNumberFactory('add', addNumber);
|
52
52
|
export { createHypot } from './function/arithmetic/hypot.js';
|
@@ -212,7 +212,7 @@ export { createIsPrime } from './function/utils/isPrime.js';
|
|
212
212
|
export { createNumeric } from './function/utils/numeric.js'; // json
|
213
213
|
|
214
214
|
export { createReviver } from './json/reviver.js';
|
215
|
-
export { createReplacer } from './json/replacer.js'; // helper
|
215
|
+
export { createReplacer } from './json/replacer.js'; // helper functions to create a factory function for a function which only needs typed-function
|
216
216
|
|
217
217
|
function createNumberFactory(name, fn) {
|
218
218
|
return factory(name, ['typed'], _ref => {
|
@@ -221,4 +221,16 @@ function createNumberFactory(name, fn) {
|
|
221
221
|
} = _ref;
|
222
222
|
return typed(fn);
|
223
223
|
});
|
224
|
+
}
|
225
|
+
|
226
|
+
function createNumberOptionalSecondArgFactory(name, fn) {
|
227
|
+
return factory(name, ['typed'], _ref2 => {
|
228
|
+
var {
|
229
|
+
typed
|
230
|
+
} = _ref2;
|
231
|
+
return typed({
|
232
|
+
number: fn,
|
233
|
+
'number,number': fn
|
234
|
+
});
|
235
|
+
});
|
224
236
|
}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { factory } from '../../utils/factory.js';
|
2
|
+
import { isNumber } from '../../utils/is.js';
|
2
3
|
var name = 'stirlingS2';
|
3
|
-
var dependencies = ['typed', 'addScalar', 'subtract', 'multiplyScalar', 'divideScalar', 'pow', 'factorial', 'combinations', 'isNegative', 'isInteger', 'larger'];
|
4
|
+
var dependencies = ['typed', 'addScalar', 'subtract', 'multiplyScalar', 'divideScalar', 'pow', 'factorial', 'combinations', 'isNegative', 'isInteger', 'number', '?bignumber', 'larger'];
|
4
5
|
export var createStirlingS2 = /* #__PURE__ */factory(name, dependencies, _ref => {
|
5
6
|
var {
|
6
7
|
typed,
|
@@ -13,16 +14,23 @@ export var createStirlingS2 = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
13
14
|
combinations,
|
14
15
|
isNegative,
|
15
16
|
isInteger,
|
17
|
+
number,
|
18
|
+
bignumber,
|
16
19
|
larger
|
17
20
|
} = _ref;
|
18
|
-
|
21
|
+
var smallCache = [];
|
22
|
+
var bigCache = [];
|
19
23
|
/**
|
20
24
|
* The Stirling numbers of the second kind, counts the number of ways to partition
|
21
25
|
* a set of n labelled objects into k nonempty unlabelled subsets.
|
22
26
|
* stirlingS2 only takes integer arguments.
|
23
27
|
* The following condition must be enforced: k <= n.
|
24
28
|
*
|
25
|
-
* If n = k or k = 1, then s(n,k) = 1
|
29
|
+
* If n = k or k = 1 <= n, then s(n,k) = 1
|
30
|
+
* If k = 0 < n, then s(n,k) = 0
|
31
|
+
*
|
32
|
+
* Note that if either n or k is supplied as a BigNumber, the result will be
|
33
|
+
* as well.
|
26
34
|
*
|
27
35
|
* Syntax:
|
28
36
|
*
|
@@ -40,26 +48,47 @@ export var createStirlingS2 = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
40
48
|
* @param {Number | BigNumber} k Number of objects in the subset
|
41
49
|
* @return {Number | BigNumber} S(n,k)
|
42
50
|
*/
|
51
|
+
|
43
52
|
return typed(name, {
|
44
53
|
'number | BigNumber, number | BigNumber': function numberBigNumberNumberBigNumber(n, k) {
|
45
54
|
if (!isInteger(n) || isNegative(n) || !isInteger(k) || isNegative(k)) {
|
46
55
|
throw new TypeError('Non-negative integer value expected in function stirlingS2');
|
47
56
|
} else if (larger(k, n)) {
|
48
57
|
throw new TypeError('k must be less than or equal to n in function stirlingS2');
|
49
|
-
}
|
58
|
+
}
|
59
|
+
|
60
|
+
var big = !(isNumber(n) && isNumber(k));
|
61
|
+
var cache = big ? bigCache : smallCache;
|
62
|
+
var make = big ? bignumber : number;
|
63
|
+
var nn = number(n);
|
64
|
+
var nk = number(k);
|
65
|
+
/* See if we already have the value: */
|
66
|
+
|
67
|
+
if (cache[nn] && cache[nn].length > nk) {
|
68
|
+
return cache[nn][nk];
|
69
|
+
}
|
70
|
+
/* Fill the cache */
|
71
|
+
|
50
72
|
|
73
|
+
for (var m = 0; m <= nn; ++m) {
|
74
|
+
if (!cache[m]) {
|
75
|
+
cache[m] = [m === 0 ? make(1) : make(0)];
|
76
|
+
}
|
51
77
|
|
52
|
-
|
53
|
-
|
78
|
+
if (m === 0) continue;
|
79
|
+
var row = cache[m];
|
80
|
+
var prev = cache[m - 1];
|
54
81
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
82
|
+
for (var i = row.length; i <= m && i <= nk; ++i) {
|
83
|
+
if (i === m) {
|
84
|
+
row[i] = 1;
|
85
|
+
} else {
|
86
|
+
row[i] = addScalar(multiplyScalar(make(i), prev[i]), prev[i - 1]);
|
87
|
+
}
|
88
|
+
}
|
60
89
|
}
|
61
90
|
|
62
|
-
return
|
91
|
+
return cache[nn][nk];
|
63
92
|
}
|
64
93
|
});
|
65
94
|
});
|
@@ -112,15 +112,19 @@ export function lcmNumber(a, b) {
|
|
112
112
|
}
|
113
113
|
lcmNumber.signature = n2;
|
114
114
|
/**
|
115
|
-
* Calculate the logarithm of a value.
|
115
|
+
* Calculate the logarithm of a value, optionally to a given base.
|
116
116
|
* @param {number} x
|
117
|
+
* @param {number | null | undefined} base
|
117
118
|
* @return {number}
|
118
119
|
*/
|
119
120
|
|
120
|
-
export function logNumber(x) {
|
121
|
+
export function logNumber(x, y) {
|
122
|
+
if (y) {
|
123
|
+
return Math.log(x) / Math.log(y);
|
124
|
+
}
|
125
|
+
|
121
126
|
return Math.log(x);
|
122
127
|
}
|
123
|
-
logNumber.signature = n1;
|
124
128
|
/**
|
125
129
|
* Calculate the 10-base logarithm of a number
|
126
130
|
* @param {number} x
|
package/lib/esm/version.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export var version = '10.4.
|
1
|
+
export var version = '10.4.3'; // Note: This file is automatically generated when building math.js.
|
2
2
|
// Changes made in this file will be overwritten.
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "mathjs",
|
3
|
-
"version": "10.4.
|
3
|
+
"version": "10.4.3",
|
4
4
|
"description": "Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with different data types like numbers, big numbers, complex numbers, fractions, units, and matrices.",
|
5
5
|
"author": "Jos de Jong <wjosdejong@gmail.com> (https://github.com/josdejong)",
|
6
6
|
"homepage": "https://mathjs.org",
|