1
0
mirror of https://github.com/MikeMcl/decimal.js.git synced 2026-03-02 03:49:24 +00:00

Fix NaN toNumber

This commit is contained in:
Michael Mclaughlin
2014-05-08 19:27:25 +01:00
parent ba0ca1ee14
commit 800cef4c1f
3 changed files with 10 additions and 8 deletions

View File

@@ -19,14 +19,14 @@ var count = (function toNumber(Decimal) {
function assert(expected, actual) {
total++;
if (expected !== actual) {
if (expected === actual || isNaN(expected) && isNaN(actual)) {
passed++;
//log('\n Expected and actual: ' + actual);
} else {
error('\n Test number: ' + total + ' failed');
error(' Expected: ' + expected);
error(' Actual: ' + actual);
//process.exit();
} else {
passed++;
//log('\n Expected and actual: ' + actual);
}
}
@@ -35,7 +35,7 @@ var count = (function toNumber(Decimal) {
}
function T(value, n) {
assert(new Decimal(value).toNumber(), n);
assert(n, new Decimal(value).toNumber());
}
log('\n Testing toNumber...');
@@ -80,6 +80,8 @@ var count = (function toNumber(Decimal) {
T('Infinity', 1 / 0);
T(-Infinity, -1 / 0);
T('-Infinity', -1 / 0);
T(NaN, NaN);
T('NaN', NaN);
T('9.999999e+9000000000000000', 1 / 0);
T('-9.999999e+9000000000000000', -1 / 0);