diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-01-24 09:40:46 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-01-24 09:40:46 -0800 |
commit | ff6dfa8bd32383accdb1a84e9e350cb0b27a6abd (patch) | |
tree | bad48d2a5e42996dc47e07ccbfcd463064c3c2c3 /lib/Target/JSBackend/JSBackend.cpp | |
parent | 30fb3ff89104c2a4112f54740722c43f42286f74 (diff) | |
parent | 59a972faa293266371a78dc34f4b1d7eabb1932a (diff) |
Merge pull request #7 from juj/fix_float_literals
Fix serialization of nans, infs and negative floats to JS.
Diffstat (limited to 'lib/Target/JSBackend/JSBackend.cpp')
-rw-r--r-- | lib/Target/JSBackend/JSBackend.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/Target/JSBackend/JSBackend.cpp b/lib/Target/JSBackend/JSBackend.cpp index c443c3bf9e..984015fffa 100644 --- a/lib/Target/JSBackend/JSBackend.cpp +++ b/lib/Target/JSBackend/JSBackend.cpp @@ -746,6 +746,10 @@ static int hexToInt(char x) { } */ static inline std::string ftostr_exact(const ConstantFP *CFP) { + const APFloat &flt = CFP->getValueAPF(); + if (flt.getCategory() == APFloat::fcInfinity) return flt.isNegative() ? "-inf" : "inf"; + else if (flt.getCategory() == APFloat::fcNaN) return "nan"; + std::string temp; raw_string_ostream stream(temp); stream << *CFP; // bitcast on APF produces odd results, so do it this horrible way @@ -777,7 +781,9 @@ std::string JSWriter::getConstant(const Constant* CV, AsmCast sign) { } else { if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) { std::string S = ftostr_exact(CFP); - S = '+' + S; + if (S[0] != '+') { + S = '+' + S; + } //if (S.find('.') == S.npos) { TODO: do this when necessary, but it is necessary even for 0.0001 return S; } else if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) { |