[llvm-commits] [llvm] r141816 - in /llvm/trunk: lib/Support/APFloat.cpp unittests/ADT/APFloatTest.cpp
Eli Friedman
eli.friedman at gmail.com
Wed Oct 12 14:51:36 PDT 2011
Author: efriedma
Date: Wed Oct 12 16:51:36 2011
New Revision: 141816
URL: http://llvm.org/viewvc/llvm-project?rev=141816&view=rev
Log:
Fix APFloat::getLargest so that it actually returns the correct value. Found by accident while reviewing a patch to nearby code.
Modified:
llvm/trunk/lib/Support/APFloat.cpp
llvm/trunk/unittests/ADT/APFloatTest.cpp
Modified: llvm/trunk/lib/Support/APFloat.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APFloat.cpp?rev=141816&r1=141815&r2=141816&view=diff
==============================================================================
--- llvm/trunk/lib/Support/APFloat.cpp (original)
+++ llvm/trunk/lib/Support/APFloat.cpp Wed Oct 12 16:51:36 2011
@@ -3243,8 +3243,9 @@
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;
}
Modified: llvm/trunk/unittests/ADT/APFloatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/APFloatTest.cpp?rev=141816&r1=141815&r2=141816&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/APFloatTest.cpp (original)
+++ llvm/trunk/unittests/ADT/APFloatTest.cpp Wed Oct 12 16:51:36 2011
@@ -648,4 +648,9 @@
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());
+}
+
}
More information about the llvm-commits
mailing list