summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Support/APFloat.cpp5
-rw-r--r--unittests/ADT/APFloatTest.cpp5
2 files changed, 8 insertions, 2 deletions
diff --git a/lib/Support/APFloat.cpp b/lib/Support/APFloat.cpp
index 5307829ed8..95df8617fb 100644
--- a/lib/Support/APFloat.cpp
+++ b/lib/Support/APFloat.cpp
@@ -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;
}
diff --git a/unittests/ADT/APFloatTest.cpp b/unittests/ADT/APFloatTest.cpp
index 3c40a13d36..e70c5f7af2 100644
--- a/unittests/ADT/APFloatTest.cpp
+++ b/unittests/ADT/APFloatTest.cpp
@@ -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());
+}
+
}