Add isInteger() to APFloat.
[oota-llvm.git] / lib / Support / APFloat.cpp
index 91b3db59d0e3d82e02271a07acf2339c1b6f1087..19b8221b60cb55389d7c9858fe93d0595c5e2c54 100644 (file)
@@ -767,6 +767,15 @@ APFloat::isLargest() 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)