mathjs 12.3.0 → 12.3.2
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 +27 -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/expression/node/OperatorNode.js +2 -1
- package/lib/cjs/expression/transform/utils/compileInlineExpression.js +5 -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/map.js +174 -14
- package/lib/cjs/utils/number.js +75 -33
- package/lib/cjs/utils/scope.js +4 -10
- 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/expression/node/OperatorNode.js +2 -1
- package/lib/esm/expression/transform/utils/compileInlineExpression.js +5 -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/map.js +97 -1
- package/lib/esm/utils/number.js +76 -34
- package/lib/esm/utils/scope.js +5 -11
- package/lib/esm/version.js +1 -1
- package/package.json +12 -12
- 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';
|
@@ -13,6 +13,7 @@ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits
|
|
13
13
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
14
14
|
var _is = require("../../utils/is.js");
|
15
15
|
var _array = require("../../utils/array.js");
|
16
|
+
var _scope = require("../../utils/scope.js");
|
16
17
|
var _string = require("../../utils/string.js");
|
17
18
|
var _customs = require("../../utils/customs.js");
|
18
19
|
var _operators = require("../operators.js");
|
@@ -311,7 +312,7 @@ var createOperatorNode = exports.createOperatorNode = /* #__PURE__ */(0, _factor
|
|
311
312
|
// "raw" evaluation
|
312
313
|
var rawArgs = this.args;
|
313
314
|
return function evalOperatorNode(scope, args, context) {
|
314
|
-
return fn(rawArgs, math, scope);
|
315
|
+
return fn(rawArgs, math, (0, _scope.createSubScope)(scope, args));
|
315
316
|
};
|
316
317
|
} else if (evalArgs.length === 1) {
|
317
318
|
var evalArg0 = evalArgs[0];
|
@@ -5,12 +5,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.compileInlineExpression = compileInlineExpression;
|
7
7
|
var _is = require("../../../utils/is.js");
|
8
|
-
var
|
8
|
+
var _map = require("../../../utils/map.js");
|
9
9
|
/**
|
10
10
|
* Compile an inline expression like "x > 0"
|
11
11
|
* @param {Node} expression
|
12
12
|
* @param {Object} math
|
13
|
-
* @param {
|
13
|
+
* @param {Map} scope
|
14
14
|
* @return {function} Returns a function with one argument which fills in the
|
15
15
|
* undefined variable (like "x") and evaluates the expression
|
16
16
|
*/
|
@@ -25,10 +25,11 @@ function compileInlineExpression(expression, math, scope) {
|
|
25
25
|
|
26
26
|
// create a test function for this equation
|
27
27
|
var name = symbol.name; // variable name
|
28
|
-
var
|
28
|
+
var argsScope = new Map();
|
29
|
+
var subScope = new _map.PartitionedMap(scope, argsScope, new Set([name]));
|
29
30
|
var eq = expression.compile();
|
30
31
|
return function inlineExpression(x) {
|
31
|
-
|
32
|
+
argsScope.set(name, x);
|
32
33
|
return eq.evaluate(subScope);
|
33
34
|
};
|
34
35
|
}
|
@@ -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-
|
9
|
+
* @version 12.3.2
|
10
|
+
* @date 2024-02-08
|
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
|
}
|