diff options
author | alon@honor <none@none> | 2010-09-24 21:20:47 -0700 |
---|---|---|
committer | alon@honor <none@none> | 2010-09-24 21:20:47 -0700 |
commit | 597dde09b5788dc2728feb295983ae4c02b10dbb (patch) | |
tree | b12ca12810577a11fdd90cbdc75a3501c469388c | |
parent | 05b2fafe901cf658c9f1acb80757f06453aacc62 (diff) |
Infinity and NaN
-rw-r--r-- | src/parseTools.js | 7 | ||||
-rw-r--r-- | tests/runner.py | 4 |
2 files changed, 6 insertions, 5 deletions
diff --git a/src/parseTools.js b/src/parseTools.js index f0ac834c..cdd20e2f 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -327,15 +327,16 @@ function IEEEUnHex(stringy) { var a = eval('0x' + stringy.substr(0, 8)); // top half var b = eval('0x' + stringy.substr(8)); // bottom half var e = a >> ((52 - 32) & 0x7ff); // exponent + a = a & 0xfffff; if (e === 0x7ff) { if (a == 0 && b == 0) { - return Infinity; + return 'Infinity'; } else { - return NaN; + return 'NaN'; } } e -= 1023; // offset - var absolute = ((((a & 0xfffff | 0x100000) * 1.0) / Math.pow(2,52-32)) * Math.pow(2, e)) + (((b * 1.0) / Math.pow(2, 52)) * Math.pow(2, e)); + var absolute = ((((a | 0x100000) * 1.0) / Math.pow(2,52-32)) * Math.pow(2, e)) + (((b * 1.0) / Math.pow(2, 52)) * Math.pow(2, e)); return (absolute * (neg ? -1 : 1)).toString(); } diff --git a/tests/runner.py b/tests/runner.py index 1149bfd9..519494ed 100644 --- a/tests/runner.py +++ b/tests/runner.py @@ -153,11 +153,11 @@ class T(unittest.TestCase): #include <cmath> int main() { - printf("*%.2f,%.2f*\\n", M_PI, -M_PI); + printf("*%.2f,%.2f,%f*\\n", M_PI, -M_PI, 1/0.0); return 0; } ''' - self.do_test(src, '*3.14,-3.14*') + self.do_test(src, '*3.14,-3.14,Infinity*') def test_if(self): src = ''' |