mathjs 12.3.0 → 12.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HISTORY.md +19 -0
- package/lib/browser/math.js +1 -1
- package/lib/browser/math.js.LICENSE.txt +2 -2
- package/lib/browser/math.js.map +1 -1
- package/lib/cjs/entry/configReadonly.js +1 -1
- package/lib/cjs/entry/dependenciesAny/dependenciesHelpClass.generated.js +2 -2
- package/lib/cjs/entry/dependenciesNumber/dependenciesHelpClass.generated.js +2 -2
- package/lib/cjs/entry/impureFunctionsAny.generated.js +14 -14
- package/lib/cjs/entry/impureFunctionsNumber.generated.js +1 -1
- package/lib/cjs/entry/pureFunctionsAny.generated.js +11 -11
- package/lib/cjs/expression/Help.js +21 -4
- package/lib/cjs/function/string/bin.js +3 -3
- package/lib/cjs/function/string/format.js +3 -3
- package/lib/cjs/function/string/hex.js +3 -3
- package/lib/cjs/function/string/oct.js +3 -3
- package/lib/cjs/header.js +2 -2
- package/lib/cjs/type/unit/physicalConstants.js +1 -1
- package/lib/cjs/utils/bignumber/formatter.js +17 -27
- package/lib/cjs/utils/number.js +75 -33
- package/lib/cjs/version.js +1 -1
- package/lib/esm/entry/configReadonly.js +1 -1
- package/lib/esm/entry/dependenciesAny/dependenciesHelpClass.generated.js +2 -2
- package/lib/esm/entry/dependenciesNumber/dependenciesHelpClass.generated.js +2 -2
- package/lib/esm/entry/impureFunctionsAny.generated.js +16 -16
- package/lib/esm/entry/impureFunctionsNumber.generated.js +1 -1
- package/lib/esm/entry/pureFunctionsAny.generated.js +12 -12
- package/lib/esm/expression/Help.js +21 -4
- package/lib/esm/function/string/bin.js +3 -3
- package/lib/esm/function/string/format.js +3 -3
- package/lib/esm/function/string/hex.js +3 -3
- package/lib/esm/function/string/oct.js +3 -3
- package/lib/esm/type/unit/physicalConstants.js +1 -1
- package/lib/esm/utils/bignumber/formatter.js +19 -28
- package/lib/esm/utils/number.js +76 -34
- package/lib/esm/version.js +1 -1
- package/package.json +11 -11
- package/types/index.d.ts +30 -18
@@ -9,7 +9,7 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
|
|
9
9
|
var _config = require("../core/config.js");
|
10
10
|
var _config2 = require("../core/function/config.js");
|
11
11
|
// create a read-only version of config
|
12
|
-
var config = exports.config =
|
12
|
+
var config = exports.config = function config(options) {
|
13
13
|
if (options) {
|
14
14
|
throw new Error('The global config is readonly. \n' + 'Please create a mathjs instance if you want to change the default configuration. \n' + 'Example:\n' + '\n' + ' import { create, all } from \'mathjs\';\n' + ' const mathjs = create(all);\n' + ' mathjs.config({ number: \'BigNumber\' });\n');
|
15
15
|
}
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.HelpDependencies = void 0;
|
7
|
-
var
|
7
|
+
var _dependenciesEvaluateGenerated = require("./dependenciesEvaluate.generated.js");
|
8
8
|
var _factoriesAny = require("../../factoriesAny.js");
|
9
9
|
/**
|
10
10
|
* THIS FILE IS AUTO-GENERATED
|
@@ -12,6 +12,6 @@ var _factoriesAny = require("../../factoriesAny.js");
|
|
12
12
|
*/
|
13
13
|
|
14
14
|
var HelpDependencies = exports.HelpDependencies = {
|
15
|
-
|
15
|
+
evaluateDependencies: _dependenciesEvaluateGenerated.evaluateDependencies,
|
16
16
|
createHelpClass: _factoriesAny.createHelpClass
|
17
17
|
};
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.HelpDependencies = void 0;
|
7
|
-
var
|
7
|
+
var _dependenciesEvaluateGenerated = require("./dependenciesEvaluate.generated.js");
|
8
8
|
var _factoriesNumber = require("../../factoriesNumber.js");
|
9
9
|
/**
|
10
10
|
* THIS FILE IS AUTO-GENERATED
|
@@ -12,6 +12,6 @@ var _factoriesNumber = require("../../factoriesNumber.js");
|
|
12
12
|
*/
|
13
13
|
|
14
14
|
var HelpDependencies = exports.HelpDependencies = {
|
15
|
-
|
15
|
+
evaluateDependencies: _dependenciesEvaluateGenerated.evaluateDependencies,
|
16
16
|
createHelpClass: _factoriesNumber.createHelpClass
|
17
17
|
};
|
@@ -143,13 +143,6 @@ var compile = exports.compile = (0, _factoriesAny.createCompile)({
|
|
143
143
|
parse: parse,
|
144
144
|
typed: _pureFunctionsAnyGenerated.typed
|
145
145
|
});
|
146
|
-
var Help = exports.Help = (0, _factoriesAny.createHelpClass)({
|
147
|
-
parse: parse
|
148
|
-
});
|
149
|
-
var leafCount = exports.leafCount = (0, _factoriesAny.createLeafCount)({
|
150
|
-
parse: parse,
|
151
|
-
typed: _pureFunctionsAnyGenerated.typed
|
152
|
-
});
|
153
146
|
var simplifyCore = exports.simplifyCore = (0, _factoriesAny.createSimplifyCore)({
|
154
147
|
AccessorNode: AccessorNode,
|
155
148
|
ArrayNode: ArrayNode,
|
@@ -174,10 +167,8 @@ var evaluate = exports.evaluate = (0, _factoriesAny.createEvaluate)({
|
|
174
167
|
parse: parse,
|
175
168
|
typed: _pureFunctionsAnyGenerated.typed
|
176
169
|
});
|
177
|
-
var
|
178
|
-
|
179
|
-
mathWithTransform: mathWithTransform,
|
180
|
-
typed: _pureFunctionsAnyGenerated.typed
|
170
|
+
var Help = exports.Help = (0, _factoriesAny.createHelpClass)({
|
171
|
+
evaluate: evaluate
|
181
172
|
});
|
182
173
|
var Parser = exports.Parser = (0, _factoriesAny.createParserClass)({
|
183
174
|
evaluate: evaluate
|
@@ -216,6 +207,10 @@ var symbolicEqual = exports.symbolicEqual = (0, _factoriesAny.createSymbolicEqua
|
|
216
207
|
simplify: simplify,
|
217
208
|
typed: _pureFunctionsAnyGenerated.typed
|
218
209
|
});
|
210
|
+
var leafCount = exports.leafCount = (0, _factoriesAny.createLeafCount)({
|
211
|
+
parse: parse,
|
212
|
+
typed: _pureFunctionsAnyGenerated.typed
|
213
|
+
});
|
219
214
|
var parser = exports.parser = (0, _factoriesAny.createParser)({
|
220
215
|
Parser: Parser,
|
221
216
|
typed: _pureFunctionsAnyGenerated.typed
|
@@ -262,6 +257,11 @@ var derivative = exports.derivative = (0, _factoriesAny.createDerivative)({
|
|
262
257
|
simplify: simplify,
|
263
258
|
typed: _pureFunctionsAnyGenerated.typed
|
264
259
|
});
|
260
|
+
var help = exports.help = (0, _factoriesAny.createHelp)({
|
261
|
+
Help: Help,
|
262
|
+
mathWithTransform: mathWithTransform,
|
263
|
+
typed: _pureFunctionsAnyGenerated.typed
|
264
|
+
});
|
265
265
|
(0, _extends2["default"])(math, {
|
266
266
|
e: _pureFunctionsAnyGenerated.e,
|
267
267
|
"false": _pureFunctionsAnyGenerated._false,
|
@@ -539,7 +539,7 @@ var derivative = exports.derivative = (0, _factoriesAny.createDerivative)({
|
|
539
539
|
eigs: _pureFunctionsAnyGenerated.eigs,
|
540
540
|
fermiCoupling: _pureFunctionsAnyGenerated.fermiCoupling,
|
541
541
|
gasConstant: _pureFunctionsAnyGenerated.gasConstant,
|
542
|
-
|
542
|
+
kldivergence: _pureFunctionsAnyGenerated.kldivergence,
|
543
543
|
mean: _pureFunctionsAnyGenerated.mean,
|
544
544
|
molarVolume: _pureFunctionsAnyGenerated.molarVolume,
|
545
545
|
planckConstant: _pureFunctionsAnyGenerated.planckConstant,
|
@@ -548,12 +548,12 @@ var derivative = exports.derivative = (0, _factoriesAny.createDerivative)({
|
|
548
548
|
variance: _pureFunctionsAnyGenerated.variance,
|
549
549
|
classicalElectronRadius: _pureFunctionsAnyGenerated.classicalElectronRadius,
|
550
550
|
evaluate: evaluate,
|
551
|
-
help: help,
|
552
551
|
median: _pureFunctionsAnyGenerated.median,
|
553
552
|
simplify: simplify,
|
554
553
|
symbolicEqual: symbolicEqual,
|
555
554
|
corr: _pureFunctionsAnyGenerated.corr,
|
556
555
|
freqz: _pureFunctionsAnyGenerated.freqz,
|
556
|
+
leafCount: leafCount,
|
557
557
|
mad: _pureFunctionsAnyGenerated.mad,
|
558
558
|
parser: parser,
|
559
559
|
rationalize: rationalize,
|
@@ -562,7 +562,7 @@ var derivative = exports.derivative = (0, _factoriesAny.createDerivative)({
|
|
562
562
|
derivative: derivative,
|
563
563
|
norm: _pureFunctionsAnyGenerated.norm,
|
564
564
|
rotationMatrix: _pureFunctionsAnyGenerated.rotationMatrix,
|
565
|
-
|
565
|
+
help: help,
|
566
566
|
planckTime: _pureFunctionsAnyGenerated.planckTime,
|
567
567
|
schur: _pureFunctionsAnyGenerated.schur,
|
568
568
|
rotate: _pureFunctionsAnyGenerated.rotate,
|
@@ -165,7 +165,7 @@ var evaluate = exports.evaluate = (0, _factoriesNumber.createEvaluate)({
|
|
165
165
|
typed: _pureFunctionsNumberGenerated.typed
|
166
166
|
});
|
167
167
|
var Help = exports.Help = (0, _factoriesNumber.createHelpClass)({
|
168
|
-
|
168
|
+
evaluate: evaluate
|
169
169
|
});
|
170
170
|
var Parser = exports.Parser = (0, _factoriesNumber.createParserClass)({
|
171
171
|
evaluate: evaluate
|
@@ -1610,6 +1610,17 @@ var gasConstant = exports.gasConstant = /* #__PURE__ */(0, _factoriesAny.createG
|
|
1610
1610
|
Unit: Unit,
|
1611
1611
|
config: _configReadonly.config
|
1612
1612
|
});
|
1613
|
+
var kldivergence = exports.kldivergence = /* #__PURE__ */(0, _factoriesAny.createKldivergence)({
|
1614
|
+
divide: divide,
|
1615
|
+
dotDivide: dotDivide,
|
1616
|
+
isNumeric: isNumeric,
|
1617
|
+
log: log,
|
1618
|
+
map: map,
|
1619
|
+
matrix: matrix,
|
1620
|
+
multiply: multiply,
|
1621
|
+
sum: sum,
|
1622
|
+
typed: typed
|
1623
|
+
});
|
1613
1624
|
var mean = exports.mean = /* #__PURE__ */(0, _factoriesAny.createMean)({
|
1614
1625
|
add: add,
|
1615
1626
|
divide: divide,
|
@@ -1740,17 +1751,6 @@ var rotationMatrix = exports.rotationMatrix = /* #__PURE__ */(0, _factoriesAny.c
|
|
1740
1751
|
typed: typed,
|
1741
1752
|
unaryMinus: unaryMinus
|
1742
1753
|
});
|
1743
|
-
var kldivergence = exports.kldivergence = /* #__PURE__ */(0, _factoriesAny.createKldivergence)({
|
1744
|
-
divide: divide,
|
1745
|
-
dotDivide: dotDivide,
|
1746
|
-
isNumeric: isNumeric,
|
1747
|
-
log: log,
|
1748
|
-
map: map,
|
1749
|
-
matrix: matrix,
|
1750
|
-
multiply: multiply,
|
1751
|
-
sum: sum,
|
1752
|
-
typed: typed
|
1753
|
-
});
|
1754
1754
|
var planckTime = exports.planckTime = /* #__PURE__ */(0, _factoriesAny.createPlanckTime)({
|
1755
1755
|
BigNumber: BigNumber,
|
1756
1756
|
Unit: Unit,
|
@@ -9,9 +9,9 @@ var _object = require("../utils/object.js");
|
|
9
9
|
var _string = require("../utils/string.js");
|
10
10
|
var _factory = require("../utils/factory.js");
|
11
11
|
var name = 'Help';
|
12
|
-
var dependencies = ['
|
12
|
+
var dependencies = ['evaluate'];
|
13
13
|
var createHelpClass = exports.createHelpClass = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
|
14
|
-
var
|
14
|
+
var evaluate = _ref.evaluate;
|
15
15
|
/**
|
16
16
|
* Documentation object
|
17
17
|
* @param {Object} doc Object containing properties:
|
@@ -59,14 +59,26 @@ var createHelpClass = exports.createHelpClass = /* #__PURE__ */(0, _factory.fact
|
|
59
59
|
}
|
60
60
|
if (doc.examples) {
|
61
61
|
desc += 'Examples:\n';
|
62
|
-
|
62
|
+
|
63
|
+
// after evaluating the examples, we restore config in case the examples
|
64
|
+
// did change the config.
|
65
|
+
var configChanged = false;
|
66
|
+
var originalConfig = evaluate('config()');
|
67
|
+
var scope = {
|
68
|
+
config: function config(newConfig) {
|
69
|
+
configChanged = true;
|
70
|
+
return evaluate('config(newConfig)', {
|
71
|
+
newConfig: newConfig
|
72
|
+
});
|
73
|
+
}
|
74
|
+
};
|
63
75
|
for (var i = 0; i < doc.examples.length; i++) {
|
64
76
|
var expr = doc.examples[i];
|
65
77
|
desc += ' ' + expr + '\n';
|
66
78
|
var res = void 0;
|
67
79
|
try {
|
68
80
|
// note: res can be undefined when `expr` is an empty string
|
69
|
-
res =
|
81
|
+
res = evaluate(expr, scope);
|
70
82
|
} catch (e) {
|
71
83
|
res = e;
|
72
84
|
}
|
@@ -77,6 +89,11 @@ var createHelpClass = exports.createHelpClass = /* #__PURE__ */(0, _factory.fact
|
|
77
89
|
}
|
78
90
|
}
|
79
91
|
desc += '\n';
|
92
|
+
if (configChanged) {
|
93
|
+
evaluate('config(originalConfig)', {
|
94
|
+
originalConfig: originalConfig
|
95
|
+
});
|
96
|
+
}
|
80
97
|
}
|
81
98
|
if (doc.mayThrow && doc.mayThrow.length) {
|
82
99
|
desc += 'Throws: ' + doc.mayThrow.join(', ') + '\n\n';
|
@@ -25,8 +25,8 @@ var dependencies = ['typed', 'format'];
|
|
25
25
|
* oct
|
26
26
|
* hex
|
27
27
|
*
|
28
|
-
* @param {number} value Value to be stringified
|
29
|
-
* @param {number} wordSize Optional word size (see `format`)
|
28
|
+
* @param {number | BigNumber} value Value to be stringified
|
29
|
+
* @param {number | BigNumber} wordSize Optional word size (see `format`)
|
30
30
|
* @return {string} The formatted value
|
31
31
|
*/
|
32
32
|
var createBin = exports.createBin = (0, _factory.factory)(name, dependencies, function (_ref) {
|
@@ -38,7 +38,7 @@ var createBin = exports.createBin = (0, _factory.factory)(name, dependencies, fu
|
|
38
38
|
notation: 'bin'
|
39
39
|
});
|
40
40
|
},
|
41
|
-
'number | BigNumber, number': function
|
41
|
+
'number | BigNumber, number | BigNumber': function numberBigNumberNumberBigNumber(n, wordSize) {
|
42
42
|
return format(n, {
|
43
43
|
notation: 'bin',
|
44
44
|
wordSize: wordSize
|
@@ -46,7 +46,7 @@ var createFormat = exports.createFormat = /* #__PURE__ */(0, _factory.factory)(n
|
|
46
46
|
* - `'bin'`, `'oct'`, or `'hex'`
|
47
47
|
* Format the number using binary, octal, or hexadecimal notation.
|
48
48
|
* For example `'0b1101'` and `'0x10fe'`.
|
49
|
-
* - `wordSize: number`
|
49
|
+
* - `wordSize: number | BigNumber`
|
50
50
|
* The word size in bits to use for formatting in binary, octal, or
|
51
51
|
* hexadecimal notation. To be used only with `'bin'`, `'oct'`, or `'hex'`
|
52
52
|
* values for `notation` option. When this option is defined the value
|
@@ -54,7 +54,7 @@ var createFormat = exports.createFormat = /* #__PURE__ */(0, _factory.factory)(n
|
|
54
54
|
* size and the size suffix is appended to the output.
|
55
55
|
* For example `format(-1, {notation: 'hex', wordSize: 8}) === '0xffi8'`.
|
56
56
|
* Default value is undefined.
|
57
|
-
* - `precision: number`
|
57
|
+
* - `precision: number | BigNumber`
|
58
58
|
* Limit the number of digits of the formatted value.
|
59
59
|
* For regular numbers, must be a number between `0` and `16`.
|
60
60
|
* For bignumbers, the maximum depends on the configured precision,
|
@@ -130,6 +130,6 @@ var createFormat = exports.createFormat = /* #__PURE__ */(0, _factory.factory)(n
|
|
130
130
|
*/
|
131
131
|
return typed(name, {
|
132
132
|
any: _string.format,
|
133
|
-
'any, Object | function | number': _string.format
|
133
|
+
'any, Object | function | number | BigNumber': _string.format
|
134
134
|
});
|
135
135
|
});
|
@@ -24,8 +24,8 @@ var dependencies = ['typed', 'format'];
|
|
24
24
|
* oct
|
25
25
|
* bin
|
26
26
|
*
|
27
|
-
* @param {number} value Value to be stringified
|
28
|
-
* @param {number} wordSize Optional word size (see `format`)
|
27
|
+
* @param {number | BigNumber} value Value to be stringified
|
28
|
+
* @param {number | BigNumber} wordSize Optional word size (see `format`)
|
29
29
|
* @return {string} The formatted value
|
30
30
|
*/
|
31
31
|
var createHex = exports.createHex = (0, _factory.factory)(name, dependencies, function (_ref) {
|
@@ -37,7 +37,7 @@ var createHex = exports.createHex = (0, _factory.factory)(name, dependencies, fu
|
|
37
37
|
notation: 'hex'
|
38
38
|
});
|
39
39
|
},
|
40
|
-
'number | BigNumber, number': function
|
40
|
+
'number | BigNumber, number | BigNumber': function numberBigNumberNumberBigNumber(n, wordSize) {
|
41
41
|
return format(n, {
|
42
42
|
notation: 'hex',
|
43
43
|
wordSize: wordSize
|
@@ -25,8 +25,8 @@ var dependencies = ['typed', 'format'];
|
|
25
25
|
* bin
|
26
26
|
* hex
|
27
27
|
*
|
28
|
-
* @param {number} value Value to be stringified
|
29
|
-
* @param {number} wordSize Optional word size (see `format`)
|
28
|
+
* @param {number | BigNumber} value Value to be stringified
|
29
|
+
* @param {number | BigNumber} wordSize Optional word size (see `format`)
|
30
30
|
* @return {string} The formatted value
|
31
31
|
*/
|
32
32
|
|
@@ -39,7 +39,7 @@ var createOct = exports.createOct = (0, _factory.factory)(name, dependencies, fu
|
|
39
39
|
notation: 'oct'
|
40
40
|
});
|
41
41
|
},
|
42
|
-
'number | BigNumber, number': function
|
42
|
+
'number | BigNumber, number | BigNumber': function numberBigNumberNumberBigNumber(n, wordSize) {
|
43
43
|
return format(n, {
|
44
44
|
notation: 'oct',
|
45
45
|
wordSize: wordSize
|
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 12.3.
|
10
|
-
* @date 2024-01
|
9
|
+
* @version 12.3.1
|
10
|
+
* @date 2024-02-01
|
11
11
|
*
|
12
12
|
* @license
|
13
13
|
* Copyright (C) 2013-2024 Jos de Jong <wjosdejong@gmail.com>
|
@@ -49,7 +49,7 @@ var createAvogadro = exports.createAvogadro = /* #__PURE__ */unitFactory('avogad
|
|
49
49
|
var createBoltzmann = exports.createBoltzmann = /* #__PURE__ */unitFactory('boltzmann', '1.380649e-23', 'J K^-1');
|
50
50
|
var createFaraday = exports.createFaraday = /* #__PURE__ */unitFactory('faraday', '96485.33212331001', 'C mol^-1');
|
51
51
|
var createFirstRadiation = exports.createFirstRadiation = /* #__PURE__ */unitFactory('firstRadiation', '3.7417718521927573e-16', 'W m^2');
|
52
|
-
//
|
52
|
+
// TODO spectralRadiance = 1.1910429723971881e-16 W m^2 sr^-1
|
53
53
|
var createLoschmidt = exports.createLoschmidt = /* #__PURE__ */unitFactory('loschmidt', '2.686780111798444e25', 'm^-3');
|
54
54
|
var createGasConstant = exports.createGasConstant = /* #__PURE__ */unitFactory('gasConstant', '8.31446261815324', 'J K^-1 mol^-1');
|
55
55
|
var createMolarPlanckConstant = exports.createMolarPlanckConstant = /* #__PURE__ */unitFactory('molarPlanckConstant', '3.990312712893431e-10', 'J s mol^-1');
|
@@ -7,6 +7,7 @@ exports.format = format;
|
|
7
7
|
exports.toEngineering = toEngineering;
|
8
8
|
exports.toExponential = toExponential;
|
9
9
|
exports.toFixed = toFixed;
|
10
|
+
var _is = require("../is.js");
|
10
11
|
var _number = require("../number.js");
|
11
12
|
/**
|
12
13
|
* Formats a BigNumber in a given base
|
@@ -127,7 +128,7 @@ function formatBigNumberToBase(n, base, size) {
|
|
127
128
|
* format(12400, {notation: 'engineering'}) // returns '12.400e+3'
|
128
129
|
*
|
129
130
|
* @param {BigNumber} value
|
130
|
-
* @param {Object | Function | number} [options]
|
131
|
+
* @param {Object | Function | number | BigNumber} [options]
|
131
132
|
* @return {string} str The formatted value
|
132
133
|
*/
|
133
134
|
function format(value, options) {
|
@@ -140,30 +141,10 @@ function format(value, options) {
|
|
140
141
|
if (!value.isFinite()) {
|
141
142
|
return value.isNaN() ? 'NaN' : value.gt(0) ? 'Infinity' : '-Infinity';
|
142
143
|
}
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
var wordSize;
|
148
|
-
if (options !== undefined) {
|
149
|
-
// determine notation from options
|
150
|
-
if (options.notation) {
|
151
|
-
notation = options.notation;
|
152
|
-
}
|
153
|
-
|
154
|
-
// determine precision from options
|
155
|
-
if (typeof options === 'number') {
|
156
|
-
precision = options;
|
157
|
-
} else if (options.precision !== undefined) {
|
158
|
-
precision = options.precision;
|
159
|
-
}
|
160
|
-
if (options.wordSize) {
|
161
|
-
wordSize = options.wordSize;
|
162
|
-
if (typeof wordSize !== 'number') {
|
163
|
-
throw new Error('Option "wordSize" must be a number');
|
164
|
-
}
|
165
|
-
}
|
166
|
-
}
|
144
|
+
var _normalizeFormatOptio = (0, _number.normalizeFormatOptions)(options),
|
145
|
+
notation = _normalizeFormatOptio.notation,
|
146
|
+
precision = _normalizeFormatOptio.precision,
|
147
|
+
wordSize = _normalizeFormatOptio.wordSize;
|
167
148
|
|
168
149
|
// handle the various notations
|
169
150
|
switch (notation) {
|
@@ -183,8 +164,8 @@ function format(value, options) {
|
|
183
164
|
{
|
184
165
|
// determine lower and upper bound for exponential notation.
|
185
166
|
// TODO: implement support for upper and lower to be BigNumbers themselves
|
186
|
-
var lowerExp = options
|
187
|
-
var upperExp = options
|
167
|
+
var lowerExp = _toNumberOrDefault(options === null || options === void 0 ? void 0 : options.lowerExp, -3);
|
168
|
+
var upperExp = _toNumberOrDefault(options === null || options === void 0 ? void 0 : options.upperExp, 5);
|
188
169
|
|
189
170
|
// handle special case zero
|
190
171
|
if (value.isZero()) return '0';
|
@@ -257,4 +238,13 @@ function toExponential(value, precision) {
|
|
257
238
|
*/
|
258
239
|
function toFixed(value, precision) {
|
259
240
|
return value.toFixed(precision);
|
241
|
+
}
|
242
|
+
function _toNumberOrDefault(value, defaultValue) {
|
243
|
+
if ((0, _is.isNumber)(value)) {
|
244
|
+
return value;
|
245
|
+
} else if ((0, _is.isBigNumber)(value)) {
|
246
|
+
return value.toNumber();
|
247
|
+
} else {
|
248
|
+
return defaultValue;
|
249
|
+
}
|
260
250
|
}
|
package/lib/cjs/utils/number.js
CHANGED
@@ -12,6 +12,7 @@ exports.format = format;
|
|
12
12
|
exports.isInteger = isInteger;
|
13
13
|
exports.log2 = exports.log1p = exports.log10 = void 0;
|
14
14
|
exports.nearlyEqual = nearlyEqual;
|
15
|
+
exports.normalizeFormatOptions = normalizeFormatOptions;
|
15
16
|
exports.roundDigits = roundDigits;
|
16
17
|
exports.sinh = exports.sign = void 0;
|
17
18
|
exports.splitNumber = splitNumber;
|
@@ -42,7 +43,7 @@ function isInteger(value) {
|
|
42
43
|
* @param {number} x
|
43
44
|
* @returns {number}
|
44
45
|
*/
|
45
|
-
var sign = exports.sign =
|
46
|
+
var sign = exports.sign = Math.sign || function (x) {
|
46
47
|
if (x > 0) {
|
47
48
|
return 1;
|
48
49
|
} else if (x < 0) {
|
@@ -57,7 +58,7 @@ var sign = exports.sign = /* #__PURE__ */Math.sign || function (x) {
|
|
57
58
|
* @param {number} x
|
58
59
|
* @returns {number}
|
59
60
|
*/
|
60
|
-
var log2 = exports.log2 =
|
61
|
+
var log2 = exports.log2 = Math.log2 || function log2(x) {
|
61
62
|
return Math.log(x) / Math.LN2;
|
62
63
|
};
|
63
64
|
|
@@ -66,7 +67,7 @@ var log2 = exports.log2 = /* #__PURE__ */Math.log2 || function log2(x) {
|
|
66
67
|
* @param {number} x
|
67
68
|
* @returns {number}
|
68
69
|
*/
|
69
|
-
var log10 = exports.log10 =
|
70
|
+
var log10 = exports.log10 = Math.log10 || function log10(x) {
|
70
71
|
return Math.log(x) / Math.LN10;
|
71
72
|
};
|
72
73
|
|
@@ -75,7 +76,7 @@ var log10 = exports.log10 = /* #__PURE__ */Math.log10 || function log10(x) {
|
|
75
76
|
* @param {number} x
|
76
77
|
* @returns {number}
|
77
78
|
*/
|
78
|
-
var log1p = exports.log1p =
|
79
|
+
var log1p = exports.log1p = Math.log1p || function (x) {
|
79
80
|
return Math.log(x + 1);
|
80
81
|
};
|
81
82
|
|
@@ -88,7 +89,7 @@ var log1p = exports.log1p = /* #__PURE__ */Math.log1p || function (x) {
|
|
88
89
|
* @param {number} x
|
89
90
|
* @returns {number} Returns the cubic root of x
|
90
91
|
*/
|
91
|
-
var cbrt = exports.cbrt =
|
92
|
+
var cbrt = exports.cbrt = Math.cbrt || function cbrt(x) {
|
92
93
|
if (x === 0) {
|
93
94
|
return x;
|
94
95
|
}
|
@@ -112,7 +113,7 @@ var cbrt = exports.cbrt = /* #__PURE__ */Math.cbrt || function cbrt(x) {
|
|
112
113
|
* @param {number} x
|
113
114
|
* @return {number} res
|
114
115
|
*/
|
115
|
-
var expm1 = exports.expm1 =
|
116
|
+
var expm1 = exports.expm1 = Math.expm1 || function expm1(x) {
|
116
117
|
return x >= 2e-4 || x <= -2e-4 ? Math.exp(x) - 1 : x + x * x / 2 + x * x * x / 6;
|
117
118
|
};
|
118
119
|
|
@@ -255,30 +256,10 @@ function format(value, options) {
|
|
255
256
|
} else if (isNaN(value)) {
|
256
257
|
return 'NaN';
|
257
258
|
}
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
var wordSize;
|
263
|
-
if (options) {
|
264
|
-
// determine notation from options
|
265
|
-
if (options.notation) {
|
266
|
-
notation = options.notation;
|
267
|
-
}
|
268
|
-
|
269
|
-
// determine precision from options
|
270
|
-
if ((0, _is.isNumber)(options)) {
|
271
|
-
precision = options;
|
272
|
-
} else if ((0, _is.isNumber)(options.precision)) {
|
273
|
-
precision = options.precision;
|
274
|
-
}
|
275
|
-
if (options.wordSize) {
|
276
|
-
wordSize = options.wordSize;
|
277
|
-
if (typeof wordSize !== 'number') {
|
278
|
-
throw new Error('Option "wordSize" must be a number');
|
279
|
-
}
|
280
|
-
}
|
281
|
-
}
|
259
|
+
var _normalizeFormatOptio = normalizeFormatOptions(options),
|
260
|
+
notation = _normalizeFormatOptio.notation,
|
261
|
+
precision = _normalizeFormatOptio.precision,
|
262
|
+
wordSize = _normalizeFormatOptio.wordSize;
|
282
263
|
|
283
264
|
// handle the various notations
|
284
265
|
switch (notation) {
|
@@ -296,7 +277,7 @@ function format(value, options) {
|
|
296
277
|
return formatNumberToBase(value, 16, wordSize);
|
297
278
|
case 'auto':
|
298
279
|
// remove trailing zeros after the decimal point
|
299
|
-
return toPrecision(value, precision, options
|
280
|
+
return toPrecision(value, precision, options).replace(/((\.\d*?)(0+))($|e)/, function () {
|
300
281
|
var digits = arguments[2];
|
301
282
|
var e = arguments[4];
|
302
283
|
return digits !== '.' ? digits + e : e;
|
@@ -306,6 +287,49 @@ function format(value, options) {
|
|
306
287
|
}
|
307
288
|
}
|
308
289
|
|
290
|
+
/**
|
291
|
+
* Normalize format options into an object:
|
292
|
+
* {
|
293
|
+
* notation: string,
|
294
|
+
* precision: number | undefined,
|
295
|
+
* wordSize: number | undefined
|
296
|
+
* }
|
297
|
+
*/
|
298
|
+
function normalizeFormatOptions(options) {
|
299
|
+
// default values for options
|
300
|
+
var notation = 'auto';
|
301
|
+
var precision;
|
302
|
+
var wordSize;
|
303
|
+
if (options !== undefined) {
|
304
|
+
if ((0, _is.isNumber)(options)) {
|
305
|
+
precision = options;
|
306
|
+
} else if ((0, _is.isBigNumber)(options)) {
|
307
|
+
precision = options.toNumber();
|
308
|
+
} else if ((0, _is.isObject)(options)) {
|
309
|
+
if (options.precision !== undefined) {
|
310
|
+
precision = _toNumberOrThrow(options.precision, function () {
|
311
|
+
throw new Error('Option "precision" must be a number or BigNumber');
|
312
|
+
});
|
313
|
+
}
|
314
|
+
if (options.wordSize !== undefined) {
|
315
|
+
wordSize = _toNumberOrThrow(options.wordSize, function () {
|
316
|
+
throw new Error('Option "wordSize" must be a number or BigNumber');
|
317
|
+
});
|
318
|
+
}
|
319
|
+
if (options.notation) {
|
320
|
+
notation = options.notation;
|
321
|
+
}
|
322
|
+
} else {
|
323
|
+
throw new Error('Unsupported type of options, number, BigNumber, or object expected');
|
324
|
+
}
|
325
|
+
}
|
326
|
+
return {
|
327
|
+
notation: notation,
|
328
|
+
precision: precision,
|
329
|
+
wordSize: wordSize
|
330
|
+
};
|
331
|
+
}
|
332
|
+
|
309
333
|
/**
|
310
334
|
* Split a number into sign, coefficients, and exponent
|
311
335
|
* @param {number | string} value
|
@@ -469,8 +493,8 @@ function toPrecision(value, precision, options) {
|
|
469
493
|
}
|
470
494
|
|
471
495
|
// determine lower and upper bound for exponential notation.
|
472
|
-
var lowerExp = options
|
473
|
-
var upperExp = options
|
496
|
+
var lowerExp = _toNumberOrDefault(options === null || options === void 0 ? void 0 : options.lowerExp, -3);
|
497
|
+
var upperExp = _toNumberOrDefault(options === null || options === void 0 ? void 0 : options.upperExp, 5);
|
474
498
|
var split = splitNumber(value);
|
475
499
|
var rounded = precision ? roundDigits(split, precision) : split;
|
476
500
|
if (rounded.exponent < lowerExp || rounded.exponent >= upperExp) {
|
@@ -675,4 +699,22 @@ function copysign(x, y) {
|
|
675
699
|
var signx = x > 0 ? true : x < 0 ? false : 1 / x === Infinity;
|
676
700
|
var signy = y > 0 ? true : y < 0 ? false : 1 / y === Infinity;
|
677
701
|
return signx ^ signy ? -x : x;
|
702
|
+
}
|
703
|
+
function _toNumberOrThrow(value, onError) {
|
704
|
+
if ((0, _is.isNumber)(value)) {
|
705
|
+
return value;
|
706
|
+
} else if ((0, _is.isBigNumber)(value)) {
|
707
|
+
return value.toNumber();
|
708
|
+
} else {
|
709
|
+
onError();
|
710
|
+
}
|
711
|
+
}
|
712
|
+
function _toNumberOrDefault(value, defaultValue) {
|
713
|
+
if ((0, _is.isNumber)(value)) {
|
714
|
+
return value;
|
715
|
+
} else if ((0, _is.isBigNumber)(value)) {
|
716
|
+
return value.toNumber();
|
717
|
+
} else {
|
718
|
+
return defaultValue;
|
719
|
+
}
|
678
720
|
}
|
package/lib/cjs/version.js
CHANGED
@@ -4,6 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.version = void 0;
|
7
|
-
var version = exports.version = '12.3.
|
7
|
+
var version = exports.version = '12.3.1';
|
8
8
|
// Note: This file is automatically generated when building math.js.
|
9
9
|
// Changes made in this file will be overwritten.
|
@@ -3,7 +3,7 @@ import { DEFAULT_CONFIG } from '../core/config.js';
|
|
3
3
|
import { MATRIX_OPTIONS, NUMBER_OPTIONS } from '../core/function/config.js';
|
4
4
|
|
5
5
|
// create a read-only version of config
|
6
|
-
export var config =
|
6
|
+
export var config = function config(options) {
|
7
7
|
if (options) {
|
8
8
|
throw new Error('The global config is readonly. \n' + 'Please create a mathjs instance if you want to change the default configuration. \n' + 'Example:\n' + '\n' + ' import { create, all } from \'mathjs\';\n' + ' const mathjs = create(all);\n' + ' mathjs.config({ number: \'BigNumber\' });\n');
|
9
9
|
}
|
@@ -2,9 +2,9 @@
|
|
2
2
|
* THIS FILE IS AUTO-GENERATED
|
3
3
|
* DON'T MAKE CHANGES HERE
|
4
4
|
*/
|
5
|
-
import {
|
5
|
+
import { evaluateDependencies } from './dependenciesEvaluate.generated.js';
|
6
6
|
import { createHelpClass } from '../../factoriesAny.js';
|
7
7
|
export var HelpDependencies = {
|
8
|
-
|
8
|
+
evaluateDependencies,
|
9
9
|
createHelpClass
|
10
10
|
};
|
@@ -2,9 +2,9 @@
|
|
2
2
|
* THIS FILE IS AUTO-GENERATED
|
3
3
|
* DON'T MAKE CHANGES HERE
|
4
4
|
*/
|
5
|
-
import {
|
5
|
+
import { evaluateDependencies } from './dependenciesEvaluate.generated.js';
|
6
6
|
import { createHelpClass } from '../../factoriesNumber.js';
|
7
7
|
export var HelpDependencies = {
|
8
|
-
|
8
|
+
evaluateDependencies,
|
9
9
|
createHelpClass
|
10
10
|
};
|