From d229313b7dc08e40a160ace49a38acd5be5503b3 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Sun, 29 Sep 2013 16:50:14 -0700 Subject: if not running js opts, ensure a . in asmEnsureFloat immediately --- src/parseTools.js | 17 +++++++++++++++-- src/settings.js | 2 ++ 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/parseTools.js b/src/parseTools.js index 863d6bba..7e7a8307 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -1136,7 +1136,16 @@ function asmEnsureFloat(value, type) { // ensures that a float type has either 5 if (!ASM_JS) return value; // coerce if missing a '.', or if smaller than 1, so could be 1e-5 which has no . if (type in Runtime.FLOAT_TYPES && isNumber(value) && (value.toString().indexOf('.') < 0 || Math.abs(value) < 1)) { - return '(+(' + value + '))'; + if (RUNNING_JS_OPTS) { + return '(+' + value + ')'; // JS optimizer will run, we must do +x, and it will be corrected later + } else { + // ensure a . + value = value.toString(); + if (value.indexOf('.') >= 0) return value; + var e = value.indexOf('e'); + if (e < 0) return value + '.0'; + return value.substr(0, e) + '.0' + value.substr(e); + } } else { return value; } @@ -1144,7 +1153,11 @@ function asmEnsureFloat(value, type) { // ensures that a float type has either 5 function asmInitializer(type, impl) { if (type in Runtime.FLOAT_TYPES) { - return '+0'; + if (RUNNING_JS_OPTS) { + return '+0'; + } else { + return '.0'; + } } else { return '0'; } diff --git a/src/settings.js b/src/settings.js index 5e5d50f6..6894b535 100644 --- a/src/settings.js +++ b/src/settings.js @@ -434,6 +434,8 @@ var JS_CHUNK_SIZE = 10240; // Used as a maximum size before breaking up expressi var EXPORT_NAME = 'Module'; // Global variable to export the module as for environments without a standardized module // loading system (e.g. the browser and SM shell). +var RUNNING_JS_OPTS = 0; // whether js opts will be run, after the main compiler + var COMPILER_ASSERTIONS = 0; // costly (slow) compile-time assertions var COMPILER_FASTPATHS = 1; // use fast-paths to speed up compilation -- cgit v1.2.3-18-g5258