Fix APFloat::getLargest so that it actually returns the correct value. Found by accident while reviewing a patch to nearby code.

llvm-svn: 141816
This commit is contained in:
Eli Friedman 2011-10-12 21:51:36 +00:00
parent f903c154c7
commit c53220134a
2 changed files with 8 additions and 2 deletions

View File

@ -3243,8 +3243,9 @@ APFloat APFloat::getLargest(const fltSemantics &Sem, bool Negative) {
significand[i] = ~((integerPart) 0);
// ...and then clear the top bits for internal consistency.
significand[N-1] &=
(((integerPart) 1) << ((Sem.precision % integerPartWidth) - 1)) - 1;
if (Sem.precision % integerPartWidth != 0)
significand[N-1] &=
(((integerPart) 1) << (Sem.precision % integerPartWidth)) - 1;
return Val;
}

View File

@ -648,4 +648,9 @@ TEST(APFloatTest, exactInverse) {
EXPECT_FALSE(APFloat(1.40129846e-45f).getExactInverse(0));
}
TEST(APFloatTest, getLargest) {
EXPECT_EQ(3.40282347e+38f, APFloat::getLargest(APFloat::IEEEsingle).convertToFloat());
EXPECT_EQ(1.7976931348623157e+308, APFloat::getLargest(APFloat::IEEEdouble).convertToDouble());
}
}