llvm.org GIT mirror llvm / 9eb6b4d
Fix APInt::operator*= so that it computes the correct result for large integers where there is unsigned overflow. Fix APFloat::toString so that it doesn't depend on the incorrect behavior in common cases (and computes the correct result in some rare cases). Fixes PR11086. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141441 91177308-0d34-0410-b5e6-96231b3b80d8 Eli Friedman 8 years ago
3 changed file(s) with 13 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
34543454 // <= semantics->precision + e * 137 / 59
34553455 // (log_2(5) ~ 2.321928 < 2.322034 ~ 137/59)
34563456
3457 unsigned precision = semantics->precision + 137 * texp / 59;
3457 unsigned precision = semantics->precision + (137 * texp + 136) / 59;
34583458
34593459 // Multiply significand by 5^e.
34603460 // N * 5^0101 == N * 5^(1*1) * 5^(0*2) * 5^(1*4) * 5^(0*8)
385385 clearAllBits();
386386 unsigned wordsToCopy = destWords >= getNumWords() ? getNumWords() : destWords;
387387 memcpy(pVal, dest, wordsToCopy * APINT_WORD_SIZE);
388 clearUnusedBits();
388389
389390 // delete dest array and return
390391 delete[] dest;
470471 return APInt(BitWidth, VAL * RHS.VAL);
471472 APInt Result(*this);
472473 Result *= RHS;
473 return Result.clearUnusedBits();
474 return Result;
474475 }
475476
476477 APInt APInt::operator+(const APInt& RHS) const {
440440 #endif
441441 #endif
442442
443 }
443 TEST(APIntTest, mul_clear) {
444 APInt ValA(65, -1ULL);
445 APInt ValB(65, 4);
446 APInt ValC(65, 0);
447 ValC = ValA * ValB;
448 ValA *= ValB;
449 EXPECT_EQ(ValA.toString(10, false), ValC.toString(10, false));
450 }
451
452 }