diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-11-29 17:49:36 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-11-29 17:49:36 -0800 |
commit | ed1a15edbef7a8b4c03903f04b7c918a7b876391 (patch) | |
tree | a9b5ad60f73edbc640f730f0d92b0ccfa7ed08d6 /lib/Target/CppBackend/CPPBackend.cpp | |
parent | 342f2193027ff267b5f24ebb6d2c9a16243c1558 (diff) |
emit float constants properly
Diffstat (limited to 'lib/Target/CppBackend/CPPBackend.cpp')
-rw-r--r-- | lib/Target/CppBackend/CPPBackend.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/Target/CppBackend/CPPBackend.cpp b/lib/Target/CppBackend/CPPBackend.cpp index a13dc57b5d..8bdbc5852f 100644 --- a/lib/Target/CppBackend/CPPBackend.cpp +++ b/lib/Target/CppBackend/CPPBackend.cpp @@ -1434,7 +1434,12 @@ std::string CppWriter::getConstant(const Constant* CV, Signedness sign) { return getPtrAsStr(CV); } else { if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) { - std::string S = ftostr_precise(CFP->getValueAPF().convertToDouble()); + std::string S; + if (CFP->getType()->isFloatTy()) { + S = ftostr_precise(CFP->getValueAPF().convertToFloat()); + } else { + S = ftostr_precise(CFP->getValueAPF().convertToDouble()); + } S = '+' + S; //if (S.find('.') == S.npos) { TODO: do this when necessary, but it is necessary even for 0.0001 return S; |