Skip to content

Commit 220f11c

Browse files
committed
v10.3.0
1 parent c29c80c commit 220f11c

File tree

15 files changed

+94
-79
lines changed

15 files changed

+94
-79
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
language: node_js
22
node_js:
33
- "node"
4+
- "15"
45
- "14"
56
- "13"
67
- "12"

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
#### 10.3.0
2+
* 22/06/2021
3+
* Support underscores as separators.
4+
* #101 Add `Decimal.clamp` method.
5+
* #161 Fix Decimal instances deemed plain objects.
6+
* #100 Add `Decimal.sum` method.
7+
* #146 `Symbol.for` to `Symbol['for']` for IE8.
8+
* #132 Fix possible infinite loop when `minE` is very low.
9+
* #180 Accept Decimals of different origin.
10+
* Update Typescript definitions.
11+
* Update minification examples in *README*.
12+
* Add minified versions for both *decimal.js* and *decimal.mjs*.
13+
* Add *files* field to *package.json*, and remove build script.
14+
115
#### 10.2.1
216
* 28/09/2020
317
* Correct `sqrt` initial estimate.

LICENCE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT Licence.
22

3-
Copyright (c) 2020 Michael Mclaughlin
3+
Copyright (c) 2021 Michael Mclaughlin
44

55
Permission is hereby granted, free of charge, to any person obtaining
66
a copy of this software and associated documentation files (the

README.md

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ This library also adds the trigonometric functions, among others, and supports n
3232
which makes it a significantly larger library than *bignumber.js* and the even smaller
3333
[big.js](https://github.com/MikeMcl/big.js/).
3434

35-
For a lighter version of this library without the trigonometric functions see [decimal.js-light](https://github.com/MikeMcl/decimal.js-light/).
35+
For a lighter version of this library without the trigonometric functions see
36+
[decimal.js-light](https://github.com/MikeMcl/decimal.js-light/).
3637

3738
## Load
3839

@@ -43,7 +44,7 @@ Browser:
4344
```html
4445
<script src='path/to/decimal.js'></script>
4546
```
46-
47+
or
4748
```html
4849
<script type="module">
4950
import Decimal from './path/to/decimal.mjs';
@@ -54,26 +55,18 @@ import Decimal from './path/to/decimal.mjs';
5455
[Node.js](https://nodejs.org):
5556

5657
```bash
57-
$ npm install decimal.js
58+
npm install decimal.js
5859
```
59-
6060
```js
6161
var Decimal = require('decimal.js');
6262
```
63-
64-
ES module:
65-
63+
or
6664
```js
67-
//import Decimal from 'decimal.js';
68-
import {Decimal} from 'decimal.js';
65+
import Decimal from 'decimal.js';
6966
```
70-
71-
AMD loader libraries such as [requireJS](https://requirejs.org/):
72-
67+
or
7368
```js
74-
require(['decimal'], function(Decimal) {
75-
// Use Decimal here in local scope. No global Decimal.
76-
});
69+
import {Decimal} from 'decimal.js';
7770
```
7871

7972
## Use
@@ -165,11 +158,11 @@ pi.toFraction() // [ '7853982301', '2500000000' ]
165158
pi.toFraction(1000) // [ '355', '113' ]
166159
```
167160

168-
All calculations are rounded according to the number of significant digits and rounding mode
169-
specified by the `precision` and `rounding` properties of the Decimal constructor.
161+
All calculations are rounded according to the number of significant digits and rounding mode specified
162+
by the `precision` and `rounding` properties of the Decimal constructor.
170163

171-
For advanced usage, multiple Decimal constructors can be created, each with their own independent configuration which
172-
applies to all Decimal numbers created from it.
164+
For advanced usage, multiple Decimal constructors can be created, each with their own independent
165+
configuration which applies to all Decimal numbers created from it.
173166

174167
```js
175168
// Set the precision and rounding of the default Decimal constructor
@@ -206,36 +199,42 @@ and the file *test.html* which runs all the tests when opened in a browser.
206199
To run all the tests, from a command-line at the root directory using npm
207200

208201
```bash
209-
$ npm test
202+
npm test
210203
```
211204

212205
or at the *test* directory using Node
213206

214207
```bash
215-
$ node test
208+
node test
216209
```
217210

218211
Each separate test module can also be executed individually, for example, at the *test/modules* directory
219212

220213
```bash
221-
$ node toFraction
214+
node toFraction
222215
```
223216

224-
## Build
217+
## Minify
225218

226-
For Node, if [uglify-js](https://github.com/mishoo/UglifyJS2) is installed
219+
The minified version of *decimal.js* and its associated source map found in this repository was created with
220+
[uglify-js](https://github.com/mishoo/UglifyJS) using
227221

228222
```bash
229223
npm install uglify-js -g
224+
uglifyjs decimal.js --source-map url=decimal.min.js.map --compress --mangle --output decimal.min.js
230225
```
231226

232-
then
227+
The minified version of *decimal.mjs* and its associated source map found in this repository was created with
228+
[terser](https://github.com/terser/terser) using
233229

234230
```bash
235-
npm run build
231+
npm install terser -g
232+
terser decimal.mjs --source-map url=decimal.min.mjs.map -c -m --toplevel -o decimal.min.mjs
236233
```
237234

238-
will create *decimal.min.js* and a source map.
235+
```js
236+
import Decimal from './decimal.min.mjs';
237+
```
239238

240239
## Licence
241240

decimal.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export declare class Decimal {
5656
readonly d: number[];
5757
readonly e: number;
5858
readonly s: number;
59-
private readonly name: string;
59+
private readonly toStringTag: string;
6060

6161
constructor(n: Decimal.Value);
6262

decimal.global.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export declare class Decimal {
7777
readonly d: number[];
7878
readonly e: number;
7979
readonly s: number;
80-
private readonly name: string;
80+
private readonly toStringTag: string;
8181

8282
constructor(n: DecimalValue);
8383

decimal.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44

55
/*
6-
* decimal.js v10.2.1
6+
* decimal.js v10.3.0
77
* An arbitrary-precision Decimal type for JavaScript.
88
* https://github.com/MikeMcl/decimal.js
9-
* Copyright (c) 2020 Michael Mclaughlin <M8ch88l@gmail.com>
9+
* Copyright (c) 2021 Michael Mclaughlin <M8ch88l@gmail.com>
1010
* MIT Licence
1111
*/
1212

@@ -105,6 +105,7 @@
105105
invalidArgument = decimalError + 'Invalid argument: ',
106106
precisionLimitExceeded = decimalError + 'Precision limit exceeded',
107107
cryptoUnavailable = decimalError + 'crypto unavailable',
108+
tag = '[object Decimal]',
108109

109110
mathfloor = Math.floor,
110111
mathpow = Math.pow,
@@ -122,7 +123,7 @@
122123
PI_PRECISION = PI.length - 1,
123124

124125
// Decimal.prototype object
125-
P = { name: '[object Decimal]' };
126+
P = { toStringTag: tag };
126127

127128

128129
// Decimal prototype methods
@@ -227,7 +228,8 @@
227228
Ctor = x.constructor;
228229
min = new Ctor(min);
229230
max = new Ctor(max);
230-
if (!min.s || !max.s || min.gt(max)) return new Ctor(NaN);
231+
if (!min.s || !max.s) return new Ctor(NaN);
232+
if (min.gt(max)) throw Error(invalidArgument + max);
231233
k = x.cmp(min);
232234
return k < 0 ? min : x.cmp(max) > 0 ? max : new Ctor(x);
233235
};
@@ -3596,7 +3598,7 @@
35963598
*/
35973599
function parseOther(x, str) {
35983600
var base, Ctor, divisor, i, isFloat, len, p, xd, xe;
3599-
3601+
36003602
if (str.indexOf('_') > -1) {
36013603
str = str.replace(/(\d)_(?=\d)/g, '$1');
36023604
if (isDecimal.test(str)) return parseDecimal(x, str);
@@ -4530,7 +4532,7 @@
45304532
*
45314533
*/
45324534
function isDecimalInstance(obj) {
4533-
return obj instanceof Decimal || obj && obj.name === '[object Decimal]' || false;
4535+
return obj instanceof Decimal || obj && obj.toStringTag === tag || false;
45344536
}
45354537

45364538

decimal.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

decimal.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

decimal.min.mjs

Lines changed: 2 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)