Fix two APFloat bugs in converting hexadecimal constants.
authorDaniel Dunbar <daniel@zuster.org>
Thu, 20 Aug 2009 17:12:33 +0000 (17:12 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Thu, 20 Aug 2009 17:12:33 +0000 (17:12 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79540 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/APFloat.cpp
unittests/ADT/APFloatTest.cpp

index d15a21b4ff768f9a97c1ee5504f07304bc9fb1fb..c13231d3fe10ffc2f51ca60a1280e77d4d7b0451 100644 (file)
@@ -2153,7 +2153,7 @@ APFloat::convertFromHexadecimalString(const StringRef &s,
     integerPart hex_value;
 
     if(*p == '.') {
-      assert(dot == 0);
+      assert(dot == s.end());
       dot = p++;
     }
 
@@ -2190,7 +2190,7 @@ APFloat::convertFromHexadecimalString(const StringRef &s,
     int expAdjustment;
 
     /* Implicit hexadecimal point?  */
-    if(!dot)
+    if (dot == s.end())
       dot = p;
 
     /* Calculate the exponent adjustment implicit in the number of
index b97810bec4deafeb3f6f6c5bb5f1639945a6a479..7b947c5813d942d725e3d0a1e75a8305d5bbb3d0 100644 (file)
@@ -60,6 +60,8 @@ TEST(APFloatTest, fromString) {
   EXPECT_EQ(0.0,  APFloat(APFloat::IEEEdouble, "0x0000.00000p1234").convertToDouble());
   EXPECT_EQ(0.0,  APFloat(APFloat::IEEEdouble, "0x.00000p1234").convertToDouble());
   EXPECT_EQ(0.0,  APFloat(APFloat::IEEEdouble, "0x0.p1234").convertToDouble());
+  EXPECT_EQ(1.0625,  APFloat(APFloat::IEEEdouble, "0x1.1p0").convertToDouble());
+  EXPECT_EQ(1.0,  APFloat(APFloat::IEEEdouble, "0x1p0").convertToDouble());
 
   EXPECT_EQ(0.0,  APFloat(APFloat::IEEEdouble, StringRef("0e1\02", 3)).convertToDouble());
 }