diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2007-03-01 20:39:01 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2007-03-01 20:39:01 +0000 |
commit | 53ee4f9d4083ce5106d95ab23985570a1f7413e5 (patch) | |
tree | 4abb51083a9a8be9bbce5b6da3e4051f0bbdede6 | |
parent | bb9723bd980753702527ad037a700fd9a4c9f247 (diff) |
Add doubleToBits and floatToBits methods.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34807 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/ADT/APInt.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/include/llvm/ADT/APInt.h b/include/llvm/ADT/APInt.h index 7614c688c3..15652a2b71 100644 --- a/include/llvm/ADT/APInt.h +++ b/include/llvm/ADT/APInt.h @@ -723,6 +723,40 @@ public: return T.F; } + /// The conversion does not do a translation from double to integer, it just + /// re-interprets the bits of the double. Note that it is valid to do this on + /// any bit width but bits from V may get truncated. + /// @brief Converts a double to APInt bits. + APInt& doubleToBits(double V) { + union { + uint64_t I; + double D; + } T; + T.D = V; + if (isSingleWord()) + VAL = T.I; + else + pVal[0] = T.I; + return clearUnusedBits(); + } + + /// The conversion does not do a translation from float to integer, it just + /// re-interprets the bits of the float. Note that it is valid to do this on + /// any bit width but bits from V may get truncated. + /// @brief Converts a float to APInt bits. + APInt& floatToBits(float V) { + union { + uint32_t I; + float F; + } T; + T.F = V; + if (isSingleWord()) + VAL = T.I; + else + pVal[0] = T.I; + return clearUnusedBits(); + } + /// @brief Compute the square root APInt sqrt() const; }; |