long double X() { return 1.0L; }
as:
long double X()
(CompoundStmt 0xb06a00 <t.c:2:17, col:32>
(ReturnStmt 0xb068d0 <col:19, col:26>
(FloatingLiteral 0xb02cf0 <col:26> 'long double' 1.000000)))
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@52080
91177308-0d34-0410-b5e6-
96231b3b80d8
bool isExact() const { return IsExact; }
- /// getValueAsDouble - This returns the value as an inaccurate double. Note
- /// that this may cause loss of precision, but is useful for debugging dumps
- /// etc.
- double getValueAsDouble() const {
- // FIXME: We need something for long double here.
- if (cast<BuiltinType>(getType())->getKind() == BuiltinType::Float)
- return Value.convertToFloat();
- else
- return Value.convertToDouble();
- }
-
+ /// 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 getValueAsApproximateDouble() const;
+
virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
static bool classof(const Stmt *T) {
// 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) :
}
void StmtDumper::VisitFloatingLiteral(FloatingLiteral *Node) {
DumpExpr(Node);
- fprintf(F, " %f", Node->getValueAsDouble());
+ fprintf(F, " %f", Node->getValueAsApproximateDouble());
}
void StmtDumper::VisitStringLiteral(StringLiteral *Str) {
}
void StmtPrinter::VisitFloatingLiteral(FloatingLiteral *Node) {
// FIXME: print value more precisely.
- OS << Node->getValueAsDouble();
+ OS << Node->getValueAsApproximateDouble();
}
void StmtPrinter::VisitImaginaryLiteral(ImaginaryLiteral *Node) {