if (isNeg)
str++, slen--;
assert((slen <= numbits || radix != 2) && "Insufficient bit width");
- assert((slen*3 <= numbits || radix != 8) && "Insufficient bit width");
- assert((slen*4 <= numbits || radix != 16) && "Insufficient bit width");
- assert(((slen*64)/22 <= numbits || radix != 10) && "Insufficient bit width");
+ assert(((slen-1)*3 <= numbits || radix != 8) && "Insufficient bit width");
+ assert(((slen-1)*4 <= numbits || radix != 16) && "Insufficient bit width");
+ assert((((slen-1)*64)/22 <= numbits || radix != 10) && "Insufficient bit width");
// Allocate memory
if (!isSingleWord())
}
// Shift or multiply the value by the radix
- if (shift)
- *this <<= shift;
- else
- *this *= apradix;
+ if (slen > 1) {
+ if (shift)
+ *this <<= shift;
+ else
+ *this *= apradix;
+ }
// Add in the digit we just interpreted
if (apdigit.isSingleWord())
EXPECT_EQ(zero, one.srem(neg_one));
}
+TEST(APIntTest, fromString) {
+ EXPECT_EQ(APInt(1, 0), APInt(1, "0", 1, 10));
+ EXPECT_EQ(APInt(1, 1), APInt(1, "1", 1, 10));
+ EXPECT_EQ(APInt(1, 1), APInt(1, "-1", 2, 10));
+ EXPECT_EQ(APInt(1, 1), APInt(1, "1", 1, 2));
+ EXPECT_EQ(APInt(1, 1), APInt(1, "1", 1, 8));
+ EXPECT_EQ(APInt(1, 1), APInt(1, "1", 1, 16));
+}
+
}