From 1bfc89baacea6f67beb0c13a8795f752577e1cc2 Mon Sep 17 00:00:00 2001 From: Stephen Canon Date: Mon, 16 Nov 2015 21:52:48 +0000 Subject: Add isInteger() to APFloat. Useful utility function; this wasn't too hard to do before, but also wasn't obviously discoverable. Make it explicit. Reviewed offline by Michael Gottesman. llvm-svn: 253254 --- llvm/lib/Support/APFloat.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'llvm/lib/Support/APFloat.cpp') diff --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp index 91b3db59d0e..19b8221b60c 100644 --- a/llvm/lib/Support/APFloat.cpp +++ b/llvm/lib/Support/APFloat.cpp @@ -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) -- cgit v1.2.3