• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1if (typeof T === 'undefined') require('../setup');
2
3T('toNumber', function () {
4
5  Decimal.config({
6    precision: 20,
7    rounding: 4,
8    toExpNeg: -7,
9    toExpPos: 21,
10    minE: -9e15,
11    maxE: 9e15
12  });
13
14  // Positive zero
15  var t = function (n) {
16    T.assert(1 / new Decimal(n).toNumber() === Infinity);
17  }
18
19  t('0');
20  t('0.0');
21  t('0.000000000000');
22  t('0e+0');
23  t('0e-0');
24  t('1e-9000000000000000')
25
26  // Negative zero
27  t = function (n) {
28    T.assert(1 / new Decimal(n).toNumber() === -Infinity);
29  }
30
31  t('-0');
32  t('-0.0');
33  t('-0.000000000000');
34  t('-0e+0');
35  t('-0e-0');
36  t('-1e-9000000000000000')
37
38  t = function (n, expected) {
39    T.assertEqual(expected, new Decimal(n).toNumber());
40  }
41
42  t(Infinity, 1 / 0);
43  t('Infinity', 1 / 0);
44  t(-Infinity, -1 / 0);
45  t('-Infinity', -1 / 0);
46  t(NaN, NaN);
47  t('NaN', NaN);
48
49  t(1, 1);
50  t('1', 1);
51  t('1.0', 1);
52  t('1e+0', 1);
53  t('1e-0', 1);
54
55  t(-1, -1);
56  t('-1', -1);
57  t('-1.0', -1);
58  t('-1e+0', -1);
59  t('-1e-0', -1);
60
61  t('123.456789876543', 123.456789876543);
62  t('-123.456789876543', -123.456789876543);
63
64  t('1.1102230246251565e-16', 1.1102230246251565e-16);
65  t('-1.1102230246251565e-16', -1.1102230246251565e-16);
66
67  t('9007199254740991', 9007199254740991);
68  t('-9007199254740991', -9007199254740991);
69
70  t('5e-324', 5e-324);
71  t('1.7976931348623157e+308', 1.7976931348623157e+308);
72
73  t('9.999999e+9000000000000000', 1 / 0);
74  t('-9.999999e+9000000000000000', -1 / 0);
75  t('1e-9000000000000000', 0);
76  t('-1e-9000000000000000', -0);
77});
78