1
0
mirror of https://github.com/MikeMcl/decimal.js.git synced 2026-09-24 12:54:47 +00:00
#122 Add custom `util.inspect()` function.
Add `Symbol.toStringTag`.
#121 Constructor: add range check for arguments of type number and Decimal.
Remove premable from uglifyjs build script.
Move *decimal.min.js.map* to root directory.
This commit is contained in:
Michael Mclaughlin
2019-02-26 23:27:35 +00:00
parent 50dc74c3cb
commit 7818dff1ca
8 changed files with 105 additions and 25 deletions

View File

@@ -1,12 +1,9 @@
/*
*
* decimal.js v10.0.2
* decimal.js v10.1.0
* An arbitrary-precision Decimal type for JavaScript.
* https://github.com/MikeMcl/decimal.js
* Copyright (c) 2018 Michael Mclaughlin <M8ch88l@gmail.com>
* Copyright (c) 2019 Michael Mclaughlin <M8ch88l@gmail.com>
* MIT Licence
* https://github.com/MikeMcl/decimal.js/LICENCE
*
*/
@@ -4256,8 +4253,27 @@ function clone(obj) {
// Duplicate.
if (v instanceof Decimal) {
x.s = v.s;
x.e = v.e;
x.d = (v = v.d) ? v.slice() : v;
if (external) {
if (!v.d || v.e > Decimal.maxE) {
// Infinity.
x.e = NaN;
x.d = null;
} else if (v.e < Decimal.minE) {
// Zero.
x.e = 0;
x.d = [0];
} else {
x.e = v.e;
x.d = v.d.slice();
}
} else {
x.e = v.e;
x.d = v.d ? v.d.slice() : v.d;
}
return;
}
@@ -4281,8 +4297,23 @@ function clone(obj) {
// Fast path for small integers.
if (v === ~~v && v < 1e7) {
for (e = 0, i = v; i >= 10; i /= 10) e++;
x.e = e;
x.d = [v];
if (external) {
if (e > Decimal.maxE) {
x.e = NaN;
x.d = null;
} else if (e < Decimal.minE) {
x.e = 0;
x.d = [0];
} else {
x.e = e;
x.d = [v];
}
} else {
x.e = e;
x.d = [v];
}
return;
// Infinity, NaN.
@@ -4785,6 +4816,9 @@ function trunc(x) {
}
P[Symbol.for('nodejs.util.inspect.custom')] = P.toString;
P[Symbol.toStringTag] = 'Decimal';
// Create and configure initial Decimal constructor.
export var Decimal = clone(DEFAULTS);