summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJeffrey Yasskin <jyasskin@google.com>2011-07-15 07:04:56 +0000
committerJeffrey Yasskin <jyasskin@google.com>2011-07-15 07:04:56 +0000
commit3d42bfbbdd26ac56ccd706d4ebee984490c72ecc (patch)
tree113144a5aa92be3e183b280dccd6c35296a4672b /lib
parenta83bba46b38c255e18ebbe1262ea339431a1ef94 (diff)
downloadllvm-3d42bfbbdd26ac56ccd706d4ebee984490c72ecc.tar.gz
llvm-3d42bfbbdd26ac56ccd706d4ebee984490c72ecc.tar.bz2
llvm-3d42bfbbdd26ac56ccd706d4ebee984490c72ecc.tar.xz
Add an APFloat::convertToInt(APSInt) function that automatically manages the
memory for the result. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135259 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Support/APFloat.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/Support/APFloat.cpp b/lib/Support/APFloat.cpp
index c3169acabb..a46cc8dfa4 100644
--- a/lib/Support/APFloat.cpp
+++ b/lib/Support/APFloat.cpp
@@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/ADT/APFloat.h"
+#include "llvm/ADT/APSInt.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/FoldingSet.h"
#include "llvm/Support/ErrorHandling.h"
@@ -2084,6 +2085,23 @@ APFloat::convertToInteger(integerPart *parts, unsigned int width,
return fs;
}
+/* Same as convertToInteger(integerPart*, ...), except the result is returned in
+ an APSInt, whose initial bit-width and signed-ness are used to determine the
+ precision of the conversion.
+ */
+APFloat::opStatus
+APFloat::convertToInteger(APSInt &result,
+ roundingMode rounding_mode, bool *isExact) const
+{
+ unsigned bitWidth = result.getBitWidth();
+ SmallVector<uint64_t, 4> parts(result.getNumWords());
+ opStatus status = convertToInteger(
+ parts.data(), bitWidth, result.isSigned(), rounding_mode, isExact);
+ // Keeps the original signed-ness.
+ result = APInt(bitWidth, parts.size(), parts.data());
+ return status;
+}
+
/* Convert an unsigned integer SRC to a floating point number,
rounding according to ROUNDING_MODE. The sign of the floating
point number is not modified. */