[llvm] r311351 - [APFloat] Fix IsInteger() for DoubleAPFloat.
Davide Italiano via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 21 09:51:54 PDT 2017
Author: davide
Date: Mon Aug 21 09:51:54 2017
New Revision: 311351
URL: http://llvm.org/viewvc/llvm-project?rev=311351&view=rev
Log:
[APFloat] Fix IsInteger() for DoubleAPFloat.
Previously, we would just assert instead.
Differential Revision: https://reviews.llvm.org/D36961
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=311351&r1=311350&r2=311351&view=diff
==============================================================================
--- llvm/trunk/lib/Support/APFloat.cpp (original)
+++ llvm/trunk/lib/Support/APFloat.cpp Mon Aug 21 09:51:54 2017
@@ -4363,10 +4363,7 @@ bool DoubleAPFloat::isLargest() const {
bool DoubleAPFloat::isInteger() const {
assert(Semantics == &semPPCDoubleDouble && "Unexpected Semantics");
- APFloat Tmp(semPPCDoubleDoubleLegacy);
- (void)Tmp.add(Floats[0], rmNearestTiesToEven);
- (void)Tmp.add(Floats[1], rmNearestTiesToEven);
- return Tmp.isInteger();
+ return Floats[0].isInteger() && Floats[1].isInteger();
}
void DoubleAPFloat::toString(SmallVectorImpl<char> &Str,
Modified: llvm/trunk/unittests/ADT/APFloatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/APFloatTest.cpp?rev=311351&r1=311350&r2=311351&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/APFloatTest.cpp (original)
+++ llvm/trunk/unittests/ADT/APFloatTest.cpp Mon Aug 21 09:51:54 2017
@@ -1349,6 +1349,24 @@ TEST(APFloatTest, isInteger) {
EXPECT_TRUE(T.isInteger());
}
+TEST(DoubleAPFloatTest, isInteger) {
+ APFloat F1(-0.0);
+ APFloat F2(-0.0);
+ llvm::detail::DoubleAPFloat T(APFloat::PPCDoubleDouble(), std::move(F1),
+ std::move(F2));
+ EXPECT_TRUE(T.isInteger());
+ APFloat F3(3.14159);
+ APFloat F4(-0.0);
+ llvm::detail::DoubleAPFloat T2(APFloat::PPCDoubleDouble(), std::move(F3),
+ std::move(F4));
+ EXPECT_FALSE(T2.isInteger());
+ APFloat F5(-0.0);
+ APFloat F6(3.14159);
+ llvm::detail::DoubleAPFloat T3(APFloat::PPCDoubleDouble(), std::move(F5),
+ std::move(F6));
+ EXPECT_FALSE(T3.isInteger());
+}
+
TEST(APFloatTest, getLargest) {
EXPECT_EQ(3.402823466e+38f, APFloat::getLargest(APFloat::IEEEsingle()).convertToFloat());
EXPECT_EQ(1.7976931348623158e+308, APFloat::getLargest(APFloat::IEEEdouble()).convertToDouble());
More information about the llvm-commits
mailing list