Enhance APFloat to retain bits of NaNs (fixes oggenc).
[oota-llvm.git] / include / llvm / ADT / StringExtras.h
index f0788a1b1147b68f9878d85dd41164ad34c182df..b56c183a79f60c28add575ad9f3ab5a2ebadb5d2 100644 (file)
@@ -15,6 +15,7 @@
 #define LLVM_ADT_STRINGEXTRAS_H
 
 #include "llvm/Support/DataTypes.h"
+#include "llvm/ADT/APFloat.h"
 #include <cctype>
 #include <cstdio>
 #include <string>
@@ -92,6 +93,14 @@ static inline std::string ftostr(double V) {
   return B;
 }
 
+static inline std::string ftostr(APFloat V) {
+  if (&V.getSemantics() == &APFloat::IEEEsingle)
+    return ftostr(V.convertToDouble());
+  else if (&V.getSemantics() == &APFloat::IEEEdouble)
+    return ftostr((double)V.convertToFloat());
+  return 0; // error
+}
+
 static inline std::string LowercaseString(const std::string &S) {
   std::string result(S);
   for (unsigned i = 0; i < S.length(); ++i)