1 |
|
2 |
|
3 |
|
4 | var math = require('../index');
|
5 |
|
6 |
|
7 | math.config({
|
8 | number: 'BigNumber',
|
9 |
|
10 | precision: 20
|
11 | });
|
12 |
|
13 | console.log('round-off errors with numbers');
|
14 | print(math.add(0.1, 0.2));
|
15 | print(math.divide(0.3, 0.2));
|
16 | console.log();
|
17 |
|
18 | console.log('no round-off errors with BigNumbers');
|
19 | print(math.add(math.bignumber(0.1), math.bignumber(0.2)));
|
20 | print(math.divide(math.bignumber(0.3), math.bignumber(0.2)));
|
21 | console.log();
|
22 |
|
23 | console.log('create BigNumbers from strings when exceeding the range of a number');
|
24 | print(math.bignumber(1.2e+500));
|
25 | print(math.bignumber('1.2e+500'));
|
26 | console.log();
|
27 |
|
28 |
|
29 |
|
30 | console.log('use BigNumbers in the expression parser');
|
31 | print(math.eval('0.1 + 0.2'));
|
32 | print(math.eval('0.3 / 0.2'));
|
33 | console.log();
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | function print (value) {
|
41 | console.log(math.format(value));
|
42 | }
|