diff options
author | Jim Laskey <jlaskey@mac.com> | 2005-08-17 17:27:47 +0000 |
---|---|---|
committer | Jim Laskey <jlaskey@mac.com> | 2005-08-17 17:27:47 +0000 |
commit | 59b8fcfa5f736dff4a08ebcac032935b6fd92f34 (patch) | |
tree | ef971992d53fa908838320910ba39d54246b8209 /include/llvm/Support | |
parent | 9d6c45bdd71cfa6d0aace1a3d2da82d7351010eb (diff) | |
download | external_llvm-59b8fcfa5f736dff4a08ebcac032935b6fd92f34.zip external_llvm-59b8fcfa5f736dff4a08ebcac032935b6fd92f34.tar.gz external_llvm-59b8fcfa5f736dff4a08ebcac032935b6fd92f34.tar.bz2 |
Added support for converting raw bits to FP, and FP to raw bits. The intent
is to avoid the distraction of the union declarations.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22830 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Support')
-rw-r--r-- | include/llvm/Support/MathExtras.h | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/include/llvm/Support/MathExtras.h b/include/llvm/Support/MathExtras.h index ae3f752..3dcb3a3 100644 --- a/include/llvm/Support/MathExtras.h +++ b/include/llvm/Support/MathExtras.h @@ -168,6 +168,50 @@ inline unsigned Log2_64(uint64_t Value) { return 63 - CountLeadingZeros_64(Value); } +// BitsToDouble - This function takes a 64-bit integer and returns the bit +// equivalent double. +inline double BitsToDouble(uint64_t Bits) { + union { + uint64_t L; + double D; + } T; + T.L = Bits; + return T.D; +} + +// BitsToFloat - This function takes a 32-bit integer and returns the bit +// equivalent float. +inline float BitsToFloat(unsigned Bits) { + union { + unsigned I; + float F; + } T; + T.I = Bits; + return T.F; +} + +// DoubleToBits - This function takes a double and returns the bit +// equivalent 64-bit integer. +inline uint64_t DoubleToBits(double Double) { + union { + uint64_t L; + double D; + } T; + T.D = Double; + return T.L; +} + +// FloatToBits - This function takes a float and returns the bit +// equivalent 32-bit integer. +inline unsigned FloatToBits(float Float) { + union { + unsigned I; + float F; + } T; + T.F = Float; + return T.I; +} + // Platform-independent wrappers for the C99 isnan() function. int IsNAN (float f); int IsNAN (double d); |