diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-01-28 11:26:40 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-01-28 11:26:40 -0800 |
commit | d4b6c15705fc45834e9d3557c6f0796fb1e9381e (patch) | |
tree | 67b923fd9ce416e921f1d4f4e52a3e7c55096075 /src/wasm.h | |
parent | 30a371284f7a8128c52beec39ccbac03103a2b5c (diff) | |
parent | a6198ed82965e40145bc7e14096e7333a2590be6 (diff) | |
download | binaryen-d4b6c15705fc45834e9d3557c6f0796fb1e9381e.tar.gz binaryen-d4b6c15705fc45834e9d3557c6f0796fb1e9381e.tar.bz2 binaryen-d4b6c15705fc45834e9d3557c6f0796fb1e9381e.zip |
Merge pull request #151 from WebAssembly/nan
Output NaN payloads only
Diffstat (limited to 'src/wasm.h')
-rw-r--r-- | src/wasm.h | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/src/wasm.h b/src/wasm.h index 91c318034..97e0bfc12 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -58,6 +58,7 @@ #include "emscripten-optimizer/simple_ast.h" #include "mixed_arena.h" #include "pretty_printing.h" +#include "support/utilities.h" namespace wasm { @@ -190,12 +191,11 @@ struct Literal { static void printFloat(std::ostream &o, float f) { if (isnan(f)) { - union { - float ff; - uint32_t ll; - } u; - u.ff = f; - o << "nan:0x" << std::hex << u.ll << std::dec; + const char *sign = std::signbit(f) ? "-" : ""; + o << sign << "nan"; + if (uint32_t payload = ~0xffc00000u & bit_cast<uint32_t>(f)) { + o << ":0x" << std::hex << payload << std::dec; + } return; } printDouble(o, f); @@ -207,16 +207,15 @@ struct Literal { return; } if (isnan(d)) { - union { - double dd; - uint64_t ll; - } u; - u.dd = d; - o << "nan:0x" << std::hex << u.ll << std::dec; + const char *sign = std::signbit(d) ? "-" : ""; + o << sign << "nan"; + if (uint64_t payload = ~0xfff8000000000000ull & bit_cast<uint64_t>(d)) { + o << ":0x" << std::hex << payload << std::dec; + } return; } if (!std::isfinite(d)) { - o << (d < 0 ? "-infinity" : "infinity"); + o << (std::signbit(d) ? "-infinity" : "infinity"); return; } const char *text = cashew::JSPrinter::numToString(d); |