Skip to content
Browse files

cleaner fix for 0/0, 1/0, -1/0 (issue #410)

  • Loading branch information...
1 parent 2679409 commit 7c151353ef83dbef9fad71f9b895f85274bea1bb @mishoo committed Jun 6, 2012
Showing with 10 additions and 12 deletions.
  1. +10 −12 lib/process.js
View
22 lib/process.js
@@ -1408,6 +1408,15 @@ function ast_squeeze(ast, options) {
return expr[1];
}
return [ this[0], expr, MAP(args, walk) ];
+ },
+ "num": function (num) {
+ if (!isFinite(num))
+ return [ "binary", "/", num === 1 / 0
+ ? [ "num", 1 ] : num === -1 / 0
+ ? [ "unary-prefix", "-", [ "num", 1 ] ]
+ : [ "num", 0 ], [ "num", 0 ] ];
+
+ return [ this[0], num ];
}
}, function() {
for (var i = 0; i < 2; ++i) {
@@ -1576,18 +1585,7 @@ function gen_code(ast, options) {
};
function make_num(num) {
- var str, a, m;
- if (num === 1 / 0) {
- return "1/0";
- }
- if (num === -1 / 0) {
- return "-1/0";
- }
- if (isNaN(num)) {
- return "0/0";
- }
- str = num.toString(10);
- a = [ str.replace(/^0\./, ".").replace('e+', 'e') ];
+ var str = num.toString(10), a = [ str.replace(/^0\./, ".").replace('e+', 'e') ], m;
if (Math.floor(num) === num) {
if (num >= 0) {
a.push("0x" + num.toString(16).toLowerCase(), // probably pointless

0 comments on commit 7c15135

Please sign in to comment.
Something went wrong with that request. Please try again.