/// Returns true if and only if the number has the largest possible finite
/// magnitude in the current semantics.
bool isLargest() const;
+
+ /// Returns true if and only if the number is an exact integer.
+ bool isInteger() const;
/// @}
&& isSignificandAllOnes();
}
+bool
+APFloat::isInteger() const {
+ // This could be made more efficient; I'm going for obviously correct.
+ if (!isFinite()) return false;
+ APFloat truncated = *this;
+ truncated.roundToIntegral(rmTowardZero);
+ return compare(truncated) == cmpEqual;
+}
+
bool
APFloat::bitwiseIsEqual(const APFloat &rhs) const {
if (this == &rhs)
P = APFloat::getInf(APFloat::IEEEdouble, true);
P.roundToIntegral(APFloat::rmTowardZero);
EXPECT_TRUE(std::isinf(P.convertToDouble()) && P.convertToDouble() < 0.0);
-
+}
+
+TEST(APFloatTest, isInteger) {
+ APFloat T(-0.0);
+ EXPECT_TRUE(T.isInteger());
+ T = APFloat(3.14159);
+ EXPECT_FALSE(T.isInteger());
+ T = APFloat::getNaN(APFloat::IEEEdouble);
+ EXPECT_FALSE(T.isInteger());
+ T = APFloat::getInf(APFloat::IEEEdouble);
+ EXPECT_FALSE(T.isInteger());
+ T = APFloat::getInf(APFloat::IEEEdouble, true);
+ EXPECT_FALSE(T.isInteger());
+ T = APFloat::getLargest(APFloat::IEEEdouble);
+ EXPECT_TRUE(T.isInteger());
}
TEST(APFloatTest, getLargest) {