diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-08-08 20:47:39 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-08 20:47:39 -0700 |
commit | 8e8c311aaeecf9b5433e4a651585914465731f0c (patch) | |
tree | 179c9ae9f9363de4ef4aa213ee6efd52c0543663 /src | |
parent | 49b99e6675424ff0866a670ed83f2393330198dd (diff) | |
download | binaryen-8e8c311aaeecf9b5433e4a651585914465731f0c.tar.gz binaryen-8e8c311aaeecf9b5433e4a651585914465731f0c.tar.bz2 binaryen-8e8c311aaeecf9b5433e4a651585914465731f0c.zip |
in DemoteFloat64, if the truncated value is exactly at the limit, return it (#665)
and update spec tests
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm-interpreter.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index adaee0b6f..fcf03c591 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -288,6 +288,12 @@ public: double val = value.getFloat(); if (std::isnan(val)) return Literal(float(val)); if (std::isinf(val)) return Literal(float(val)); + // when close to the limit, but still truncatable to a valid value, do that + // see https://github.com/WebAssembly/sexpr-wasm-prototype/blob/2d375e8d502327e814d62a08f22da9d9b6b675dc/src/wasm-interpreter.c#L247 + uint64_t bits = value.reinterpreti64(); + if (bits > 0x47efffffe0000000ULL && bits < 0x47effffff0000000ULL) return Literal(std::numeric_limits<float>::max()); + if (bits > 0xc7efffffe0000000ULL && bits < 0xc7effffff0000000ULL) return Literal(-std::numeric_limits<float>::max()); + // when we must convert to infinity, do that if (val < -std::numeric_limits<float>::max()) return Literal(-std::numeric_limits<float>::infinity()); if (val > std::numeric_limits<float>::max()) return Literal(std::numeric_limits<float>::infinity()); return value.truncateToF32(); |