1
0
mirror of https://github.com/MikeMcl/decimal.js.git synced 2024-10-27 20:34:12 +00:00
MikeMcl_decimal.js/test/modules/toNumber.js
2016-02-04 23:52:10 +00:00

81 lines
1.5 KiB
JavaScript

if (typeof T === 'undefined') require('../setup');
(function () {
T('toNumber');
Decimal.config({
precision: 20,
rounding: 4,
toExpNeg: -7,
toExpPos: 21,
minE: -9e15,
maxE: 9e15
});
// Positive zero
var t = function (n) {
T.assert(1 / new Decimal(n).toNumber() === Infinity);
}
t('0');
t('0.0');
t('0.000000000000');
t('0e+0');
t('0e-0');
t('1e-9000000000000000')
// Negative zero
t = function (n) {
T.assert(1 / new Decimal(n).toNumber() === -Infinity);
}
t('-0');
t('-0.0');
t('-0.000000000000');
t('-0e+0');
t('-0e-0');
t('-1e-9000000000000000')
t = function (n, expected) {
T.assertEqual(expected, new Decimal(n).toNumber());
}
t(Infinity, 1 / 0);
t('Infinity', 1 / 0);
t(-Infinity, -1 / 0);
t('-Infinity', -1 / 0);
t(NaN, NaN);
t('NaN', NaN);
t(1, 1);
t('1', 1);
t('1.0', 1);
t('1e+0', 1);
t('1e-0', 1);
t(-1, -1);
t('-1', -1);
t('-1.0', -1);
t('-1e+0', -1);
t('-1e-0', -1);
t('123.456789876543', 123.456789876543);
t('-123.456789876543', -123.456789876543);
t('1.1102230246251565e-16', 1.1102230246251565e-16);
t('-1.1102230246251565e-16', -1.1102230246251565e-16);
t('9007199254740991', 9007199254740991);
t('-9007199254740991', -9007199254740991);
t('5e-324', 5e-324);
t('1.7976931348623157e+308', 1.7976931348623157e+308);
t('9.999999e+9000000000000000', 1 / 0);
t('-9.999999e+9000000000000000', -1 / 0);
t('1e-9000000000000000', 0);
t('-1e-9000000000000000', -0);
T.stop();
})();