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 | adc9c0c559eb1d8ab6929c48bf7d374e5ffbae6a (patch) | |
| tree | 9a4e10238750bb3bcfd8876cb990caa75b7f44d7 | |
| parent | 33900811eee3f2c9ec3293d7889e2d06e76b7f2b (diff) | |
| download | bcm5719-llvm-adc9c0c559eb1d8ab6929c48bf7d374e5ffbae6a.tar.gz bcm5719-llvm-adc9c0c559eb1d8ab6929c48bf7d374e5ffbae6a.zip | |
Added support for converting raw bits to FP, and FP to raw bits. The intent
is to avoid the distraction of the union declarations.
llvm-svn: 22830
| -rw-r--r-- | llvm/include/llvm/Support/MathExtras.h | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h index ae3f752cc78..3dcb3a3972c 100644 --- a/llvm/include/llvm/Support/MathExtras.h +++ b/llvm/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); |

