1
0
mirror of https://github.com/MikeMcl/decimal.js.git synced 2024-10-27 20:34:12 +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,6 +1,8 @@
language: node_js language: node_js
node_js: node_js:
- "node" - "node"
- "11"
- "10"
- "9" - "9"
- "8" - "8"
- "7" - "7"

View File

@ -1,3 +1,11 @@
#### 10.1.0
* 26/02/2019
* #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.
#### 10.0.2 #### 10.0.2
* 13/12/2018 * 13/12/2018
* #114 Remove soureMappingURL from *decimal.min.js*. * #114 Remove soureMappingURL from *decimal.min.js*.

View File

@ -1,6 +1,6 @@
The MIT Licence. The MIT Licence.
Copyright (c) 2018 Michael Mclaughlin Copyright (c) 2019 Michael Mclaughlin
Permission is hereby granted, free of charge, to any person obtaining Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the a copy of this software and associated documentation files (the

View File

@ -1,13 +1,12 @@
/*! decimal.js v10.0.2 https://github.com/MikeMcl/decimal.js/LICENCE */
;(function (globalScope) { ;(function (globalScope) {
'use strict'; 'use strict';
/* /*
* decimal.js v10.0.2 * decimal.js v10.1.0
* An arbitrary-precision Decimal type for JavaScript. * An arbitrary-precision Decimal type for JavaScript.
* https://github.com/MikeMcl/decimal.js * https://github.com/MikeMcl/decimal.js
* Copyright (c) 2018 Michael Mclaughlin <M8ch88l@gmail.com> * Copyright (c) 2019 Michael Mclaughlin <M8ch88l@gmail.com>
* MIT Licence * MIT Licence
*/ */
@ -2112,7 +2111,6 @@
}; };
/* /*
* Returns a new Decimal whose value is the nearest multiple of `y` in the direction of rounding * Returns a new Decimal whose value is the nearest multiple of `y` in the direction of rounding
* mode `rm`, or `Decimal.rounding` if `rm` is omitted, to the value of this Decimal. * mode `rm`, or `Decimal.rounding` if `rm` is omitted, to the value of this Decimal.
@ -4259,8 +4257,27 @@
// Duplicate. // Duplicate.
if (v instanceof Decimal) { if (v instanceof Decimal) {
x.s = v.s; x.s = v.s;
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.e = v.e;
x.d = (v = v.d) ? v.slice() : v; x.d = v.d.slice();
}
} else {
x.e = v.e;
x.d = v.d ? v.d.slice() : v.d;
}
return; return;
} }
@ -4284,8 +4301,23 @@
// Fast path for small integers. // Fast path for small integers.
if (v === ~~v && v < 1e7) { if (v === ~~v && v < 1e7) {
for (e = 0, i = v; i >= 10; i /= 10) e++; for (e = 0, i = v; i >= 10; i /= 10) e++;
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.e = e;
x.d = [v]; x.d = [v];
}
} else {
x.e = e;
x.d = [v];
}
return; return;
// Infinity, NaN. // Infinity, NaN.
@ -4367,7 +4399,6 @@
Decimal.tanh = tanh; // ES6 Decimal.tanh = tanh; // ES6
Decimal.trunc = trunc; // ES6 Decimal.trunc = trunc; // ES6
if (obj === void 0) obj = {}; if (obj === void 0) obj = {};
if (obj) { if (obj) {
if (obj.defaults !== true) { if (obj.defaults !== true) {
@ -4810,9 +4841,11 @@
// Node and other environments that support module.exports. // Node and other environments that support module.exports.
} else if (typeof module != 'undefined' && module.exports) { } else if (typeof module != 'undefined' && module.exports) {
Decimal.prototype[Symbol.for('nodejs.util.inspect.custom')] = function() { if (Symbol && typeof Symbol.iterator == 'symbol') {
return this.toString(); P[Symbol.for('nodejs.util.inspect.custom')] = P.toString;
}; P[Symbol.toStringTag] = 'Decimal';
}
module.exports = Decimal; module.exports = Decimal;
// Browser. // Browser.

4
decimal.min.js vendored

File diff suppressed because one or more lines are too long

1
decimal.min.js.map Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,12 +1,9 @@
/* /*
* * decimal.js v10.1.0
* decimal.js v10.0.2
* An arbitrary-precision Decimal type for JavaScript. * An arbitrary-precision Decimal type for JavaScript.
* https://github.com/MikeMcl/decimal.js * https://github.com/MikeMcl/decimal.js
* Copyright (c) 2018 Michael Mclaughlin <M8ch88l@gmail.com> * Copyright (c) 2019 Michael Mclaughlin <M8ch88l@gmail.com>
* MIT Licence * MIT Licence
* https://github.com/MikeMcl/decimal.js/LICENCE
*
*/ */
@ -4256,8 +4253,27 @@ function clone(obj) {
// Duplicate. // Duplicate.
if (v instanceof Decimal) { if (v instanceof Decimal) {
x.s = v.s; x.s = v.s;
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.e = v.e;
x.d = (v = v.d) ? v.slice() : v; x.d = v.d.slice();
}
} else {
x.e = v.e;
x.d = v.d ? v.d.slice() : v.d;
}
return; return;
} }
@ -4281,8 +4297,23 @@ function clone(obj) {
// Fast path for small integers. // Fast path for small integers.
if (v === ~~v && v < 1e7) { if (v === ~~v && v < 1e7) {
for (e = 0, i = v; i >= 10; i /= 10) e++; for (e = 0, i = v; i >= 10; i /= 10) e++;
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.e = e;
x.d = [v]; x.d = [v];
}
} else {
x.e = e;
x.d = [v];
}
return; return;
// Infinity, NaN. // 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. // Create and configure initial Decimal constructor.
export var Decimal = clone(DEFAULTS); export var Decimal = clone(DEFAULTS);

View File

@ -1,7 +1,7 @@
{ {
"name": "decimal.js", "name": "decimal.js",
"description": "An arbitrary-precision Decimal type for JavaScript.", "description": "An arbitrary-precision Decimal type for JavaScript.",
"version": "10.0.2", "version": "10.1.0",
"keywords": [ "keywords": [
"arbitrary", "arbitrary",
"precision", "precision",
@ -30,7 +30,7 @@
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"test": "node ./test/test.js", "test": "node ./test/test.js",
"build": "uglifyjs decimal.js --source-map doc/decimal.js.map -c -m -o decimal.min.js --preamble \"/* decimal.js v10.0.2 https://github.com/MikeMcl/decimal.js/LICENCE */\"" "build": "uglifyjs decimal.js --source-map url=decimal.min.js.map -c -m -o decimal.min.js"
}, },
"types": "decimal.d.ts" "types": "decimal.d.ts"
} }