summaryrefslogtreecommitdiff
path: root/src/emscripten-optimizer/simple_ast.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/emscripten-optimizer/simple_ast.h')
-rw-r--r--src/emscripten-optimizer/simple_ast.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/emscripten-optimizer/simple_ast.h b/src/emscripten-optimizer/simple_ast.h
index 62bf975f0..64aab7708 100644
--- a/src/emscripten-optimizer/simple_ast.h
+++ b/src/emscripten-optimizer/simple_ast.h
@@ -836,6 +836,19 @@ struct JSPrinter {
}
static char* numToString(double d, bool finalize=true) {
+ if (std::isnan(d)) {
+ if (std::signbit(d)) {
+ return (char*) "-NaN";
+ } else {
+ return (char*) "NaN";
+ }
+ } else if (!std::isfinite(d)) {
+ if (std::signbit(d)) {
+ return (char*) "-Infinity";
+ } else {
+ return (char*) "Infinity";
+ }
+ }
bool neg = d < 0;
if (neg) d = -d;
// try to emit the fewest necessary characters
@@ -1046,6 +1059,8 @@ struct JSPrinter {
ensure(1); // we temporarily append a 0
char *curr = buffer + last; // ensure might invalidate
buffer[used] = 0;
+ if (strstr(curr, "Infinity")) return;
+ if (strstr(curr, "NaN")) return;
if (strchr(curr, '.')) return; // already a decimal point, all good
char *e = strchr(curr, 'e');
if (!e) {