diff options
| author | Reid Spencer <rspencer@reidspencer.com> | 2007-03-01 20:06:51 +0000 |
|---|---|---|
| committer | Reid Spencer <rspencer@reidspencer.com> | 2007-03-01 20:06:51 +0000 |
| commit | f762893b9b39f064f62f65856dae3dc9dd4bddb7 (patch) | |
| tree | 711aecf9a56608d754f6a63f148685209403c62c /llvm | |
| parent | df30e2a68b83857aca93ddc2224e1f73628d0f63 (diff) | |
| download | bcm5719-llvm-f762893b9b39f064f62f65856dae3dc9dd4bddb7.tar.gz bcm5719-llvm-f762893b9b39f064f62f65856dae3dc9dd4bddb7.zip | |
Add bitsToDouble and bitsToFloat methods for re-interpretation of bits as FP.
llvm-svn: 34800
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/include/llvm/ADT/APInt.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h index 9043227f0b7..7614c688c3b 100644 --- a/llvm/include/llvm/ADT/APInt.h +++ b/llvm/include/llvm/ADT/APInt.h @@ -697,6 +697,32 @@ public: return roundToDouble(true); } + /// The conversion does not do a translation from integer to double, it just + /// re-interprets the bits as a double. Note that it is valid to do this on + /// any bit width. Exactly 64 bits will be translated. + /// @brief Converts APInt bits to a double + double bitsToDouble() const { + union { + uint64_t I; + double D; + } T; + T.I = (isSingleWord() ? VAL : pVal[0]); + return T.D; + } + + /// The conversion does not do a translation from integer to float, it just + /// re-interprets the bits as a float. Note that it is valid to do this on + /// any bit width. Exactly 32 bits will be translated. + /// @brief Converts APInt bits to a double + float bitsToFloat() const { + union { + uint32_t I; + float F; + } T; + T.I = uint32_t((isSingleWord() ? VAL : pVal[0])); + return T.F; + } + /// @brief Compute the square root APInt sqrt() const; }; |

