summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/wasm.h16
-rw-r--r--test/unit.asm.js2
-rw-r--r--test/unit.wast6
3 files changed, 22 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 << ')';
diff --git a/test/unit.asm.js b/test/unit.asm.js
index f737a3ddc..80bab6242 100644
--- a/test/unit.asm.js
+++ b/test/unit.asm.js
@@ -8,6 +8,8 @@ function () {
temp = +-2147483648;
temp = -2147483648.0;
temp = -21474836480.0;
+ temp = 0.039625;
+ temp = -0.039625;
}
function importedDoubles() {
var temp = 0.0;
diff --git a/test/unit.wast b/test/unit.wast
index 346286b18..2c16af17d 100644
--- a/test/unit.wast
+++ b/test/unit.wast
@@ -16,6 +16,12 @@
(set_local $temp
(f64.const -21474836480)
)
+ (set_local $temp
+ (f64.const 0.039625)
+ )
+ (set_local $temp
+ (f64.const -0.039625)
+ )
)
)
(func $importedDoubles