fix a critical bug in smallvector, where it would destroy elements that are
[oota-llvm.git] / include / llvm / ADT / APInt.h
index 14eee40f78fcb22927f84af32665b2d27c60f8e4..7c100a28351e55a7c2634963b6356a5028d48d17 100644 (file)
@@ -289,6 +289,9 @@ public:
   inline uint64_t getValue() {
     if (isSingleWord())
       return VAL;
+    unsigned n = getNumWords() * 64 - CountLeadingZeros();
+    if (n <= 64)
+      return pVal[0];
     assert(0 && "This APInt's bitwidth > 64");
   }
 
@@ -385,6 +388,9 @@ public:
            CountLeadingZeros();
   }
 
+  /// @brief Converts this APInt to a double value.
+  double APIntRoundToDouble(bool isSigned = false) const;
+
   /// Arithmetic right-shift this APInt by shiftAmt.
   /// @brief Arithmetic right-shift function.
   APInt ashr(unsigned shiftAmt) const;
@@ -456,6 +462,24 @@ inline unsigned LogBase2(const APInt& APIVal) {
 /// using Euclid's algorithm.
 APInt GreatestCommonDivisor(const APInt& API1, const APInt& API2);
 
+/// @brief Converts the given APInt to a double value.
+inline double APIntRoundToDouble(const APInt& APIVal, bool isSigned = false) {
+  return APIVal.APIntRoundToDouble(isSigned);
+}
+
+/// @brief Converts the given APInt to a float vlalue.
+inline float APIntRoundToFloat(const APInt& APIVal) {
+  return float(APIntRoundToDouble(APIVal));
+}
+
+/// @brief Converts the given double value into a APInt.
+APInt DoubleRoundToAPInt(double Double);
+
+/// @brief Converts the given float value into a APInt.
+inline APInt FloatRoundToAPInt(float Float) {
+  return DoubleRoundToAPInt(double(Float));
+}
+
 /// Arithmetic right-shift the APInt by shiftAmt.
 /// @brief Arithmetic right-shift function.
 inline APInt ashr(const APInt& LHS, unsigned shiftAmt) {