summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/AST/Expr.cpp10
-rw-r--r--clang/lib/AST/StmtDumper.cpp2
-rw-r--r--clang/lib/AST/StmtPrinter.cpp2
3 files changed, 12 insertions, 2 deletions
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index a89fbd621a5..78c305051ee 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -22,6 +22,16 @@ using namespace clang;
// Primary Expressions.
//===----------------------------------------------------------------------===//
+/// getValueAsApproximateDouble - This returns the value as an inaccurate
+/// double. Note that this may cause loss of precision, but is useful for
+/// debugging dumps, etc.
+double FloatingLiteral::getValueAsApproximateDouble() const {
+ llvm::APFloat V = getValue();
+ V.convert(llvm::APFloat::IEEEdouble, llvm::APFloat::rmNearestTiesToEven);
+ return V.convertToDouble();
+}
+
+
StringLiteral::StringLiteral(const char *strData, unsigned byteLength,
bool Wide, QualType t, SourceLocation firstLoc,
SourceLocation lastLoc) :
diff --git a/clang/lib/AST/StmtDumper.cpp b/clang/lib/AST/StmtDumper.cpp
index 082d2a22595..ae6ca40460a 100644
--- a/clang/lib/AST/StmtDumper.cpp
+++ b/clang/lib/AST/StmtDumper.cpp
@@ -335,7 +335,7 @@ void StmtDumper::VisitIntegerLiteral(IntegerLiteral *Node) {
}
void StmtDumper::VisitFloatingLiteral(FloatingLiteral *Node) {
DumpExpr(Node);
- fprintf(F, " %f", Node->getValueAsDouble());
+ fprintf(F, " %f", Node->getValueAsApproximateDouble());
}
void StmtDumper::VisitStringLiteral(StringLiteral *Str) {
diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp
index a740facf76f..5e347435b63 100644
--- a/clang/lib/AST/StmtPrinter.cpp
+++ b/clang/lib/AST/StmtPrinter.cpp
@@ -577,7 +577,7 @@ void StmtPrinter::VisitIntegerLiteral(IntegerLiteral *Node) {
}
void StmtPrinter::VisitFloatingLiteral(FloatingLiteral *Node) {
// FIXME: print value more precisely.
- OS << Node->getValueAsDouble();
+ OS << Node->getValueAsApproximateDouble();
}
void StmtPrinter::VisitImaginaryLiteral(ImaginaryLiteral *Node) {
OpenPOWER on IntegriCloud