aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2007-03-01 20:06:51 +0000
committerReid Spencer <rspencer@reidspencer.com>2007-03-01 20:06:51 +0000
commitab2ed8ec850b6dd9b152ab936d70b7376903168a (patch)
tree3d6ae535419c25ed54bca19267a4b851f349cb42 /include
parent1ede29c9511a50c7a9a77178e2cfff538daa0347 (diff)
downloadexternal_llvm-ab2ed8ec850b6dd9b152ab936d70b7376903168a.zip
external_llvm-ab2ed8ec850b6dd9b152ab936d70b7376903168a.tar.gz
external_llvm-ab2ed8ec850b6dd9b152ab936d70b7376903168a.tar.bz2
Add bitsToDouble and bitsToFloat methods for re-interpretation of bits as FP.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34800 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/ADT/APInt.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/include/llvm/ADT/APInt.h b/include/llvm/ADT/APInt.h
index 9043227..7614c68 100644
--- a/include/llvm/ADT/APInt.h
+++ b/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;
};