From d266b0b0a643610516eef0d5c7033e884664ecd7 Mon Sep 17 00:00:00 2001 From: jmoenig Date: Tue, 26 Nov 2013 10:40:24 +0100 Subject: fixed #245 (consistently auto-convert empty strings to zeroes) --- threads.js | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'threads.js') diff --git a/threads.js b/threads.js index 48d73ca..d08445d 100644 --- a/threads.js +++ b/threads.js @@ -98,7 +98,7 @@ function snapEquals(a, b) { } return false; } - var x = +a; + var x = +a, y = +b; if (isNaN(x) || isNaN(y)) { x = a; @@ -1842,30 +1842,30 @@ Process.prototype.reportTypeOf = function (thing) { // Process math primtives Process.prototype.reportSum = function (a, b) { - return parseFloat(a) + parseFloat(b); + return +a + (+b); }; Process.prototype.reportDifference = function (a, b) { - return parseFloat(a) - parseFloat(b); + return +a - +b; }; Process.prototype.reportProduct = function (a, b) { - return parseFloat(a) * parseFloat(b); + return +a * +b; }; Process.prototype.reportQuotient = function (a, b) { - return parseFloat(a) / parseFloat(b); + return +a / +b; }; Process.prototype.reportModulus = function (a, b) { - var x = parseFloat(a), - y = parseFloat(b); + var x = +a, + y = +b; return ((x % y) + y) % y; }; Process.prototype.reportRandom = function (min, max) { - var floor = parseFloat(min), - ceil = parseFloat(max); + var floor = +min, + ceil = +max; if ((floor % 1 !== 0) || (ceil % 1 !== 0)) { return Math.random() * (ceil - floor) + floor; } @@ -1873,8 +1873,8 @@ Process.prototype.reportRandom = function (min, max) { }; Process.prototype.reportLessThan = function (a, b) { - var x = parseFloat(a), - y = parseFloat(b); + var x = +a, + y = +b; if (isNaN(x) || isNaN(y)) { x = a; y = b; @@ -1887,8 +1887,8 @@ Process.prototype.reportNot = function (bool) { }; Process.prototype.reportGreaterThan = function (a, b) { - var x = parseFloat(a), - y = parseFloat(b); + var x = +a, + y = +b; if (isNaN(x) || isNaN(y)) { x = a; y = b; @@ -1942,11 +1942,11 @@ Process.prototype.reportFalse = function () { }; Process.prototype.reportRound = function (n) { - return Math.round(parseFloat(n)); + return Math.round(+n); }; Process.prototype.reportMonadic = function (fname, n) { - var x = parseFloat(n), + var x = +n, result = 0; switch (this.inputOption(fname)) { @@ -1990,6 +1990,7 @@ Process.prototype.reportMonadic = function (fname, n) { result = 0; break; default: + nop(); } return result; }; @@ -2021,6 +2022,7 @@ Process.prototype.reportTextFunction = function (fname, string) { result = hex_sha512(x); break; default: + nop(); } return result; }; @@ -2041,7 +2043,7 @@ Process.prototype.reportJoinWords = function (aList) { // Process string ops Process.prototype.reportLetter = function (idx, string) { - var i = parseFloat(idx || 0), + var i = +(idx || 0), str = (string || '').toString(); return str[i - 1] || ''; }; @@ -2057,7 +2059,7 @@ Process.prototype.reportUnicode = function (string) { }; Process.prototype.reportUnicodeAsLetter = function (num) { - var code = parseFloat(num || 0); + var code = +(num || 0); return String.fromCharCode(code); }; -- cgit v1.3.1