diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-10-30 16:38:33 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-10-30 16:38:33 -0700 |
commit | 9b799d7164478bf0c1463ed8ac804f65704000df (patch) | |
tree | 8df68d6b4f543de17ac74b417d4dc36279dfc334 /src | |
parent | c720a74951ef0d7f472b639c3be617a551a68df7 (diff) | |
download | binaryen-9b799d7164478bf0c1463ed8ac804f65704000df.tar.gz binaryen-9b799d7164478bf0c1463ed8ac804f65704000df.tar.bz2 binaryen-9b799d7164478bf0c1463ed8ac804f65704000df.zip |
fix float constants <1
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm.h | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/wasm.h b/src/wasm.h index 86bb91cc5..5a48aa3f2 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -166,6 +166,18 @@ struct Literal { Literal(float init) : type(WasmType::f32), f32(init) {} Literal(double init) : type(WasmType::f64), f64(init) {} + void printDouble(std::ostream &o, double d) { + const char *text = JSPrinter::numToString(d); + // spec interpreter hates floats starting with '.' + if (text[0] == '.') { + o << '0'; + } else if (text[0] == '-' && text[1] == '.') { + o << "-0"; + text++; + } + o << text; + } + friend std::ostream& operator<<(std::ostream &o, Literal literal) { o << '('; prepareMinorColor(o) << printWasmType(literal.type) << ".const "; @@ -173,8 +185,8 @@ struct Literal { case none: abort(); case WasmType::i32: o << literal.i32; break; case WasmType::i64: o << literal.i64; break; - case WasmType::f32: o << JSPrinter::numToString(literal.f32); break; - case WasmType::f64: o << JSPrinter::numToString(literal.f64); break; + case WasmType::f32: literal.printDouble(o, literal.f32); break; + case WasmType::f64: literal.printDouble(o, literal.f64); break; } restoreNormalColor(o); return o << ')'; |