1
0
mirror of https://github.com/MikeMcl/decimal.js.git synced 2024-10-27 20:34:12 +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

@ -1452,7 +1452,7 @@
var x = this;
// Ensure zero has correct sign.
return +x || ( x | 0 ) * x['s'];
return +x || ( x['s'] ? 0 * x['s'] : NaN );
};
@ -2545,7 +2545,7 @@
return x;
}
// Remove any digits after the required decimal places.
// Truncate excess digits.
if ( xc.length > sd ) {
xc.length = sd;
}

2
decimal.min.js vendored

File diff suppressed because one or more lines are too long

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);