Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 //===-- subzero/src/IceAPFloat.h - Constant float conversions --*- C++ -*--===// | |
| 2 // | |
| 3 // The LLVM Compiler Infrastructure | |
| 4 // | |
| 5 // This file is distributed under the University of Illinois Open Source | |
| 6 // License. See LICENSE.TXT for details. | |
| 7 // | |
| 8 //===----------------------------------------------------------------------===// | |
| 9 /// | |
| 10 /// \file | |
| 11 /// \brief This file implements a class to represent Subzero float and double | |
| 12 /// values. | |
| 13 /// | |
| 14 /// Note: This is a simplified version of | |
| 15 /// llvm/include/llvm/ADT/APFloat.h for use with Subzero. | |
| 16 //===----------------------------------------------------------------------===// | |
| 17 | |
| 18 #ifndef SUBZERO_SRC_ICEAPFLOAT_H | |
| 19 #define SUBZERO_SRC_ICEAPFLOAT_H | |
| 20 | |
| 21 #include "IceAPInt.h" | |
| 22 | |
| 23 namespace Ice { | |
| 24 | |
| 25 /// Takes a 32-bit Int and converts it to the corresponding float value. | |
| 26 inline float convertAPIntToFloat(const APInt &Int) { | |
| 27 assert(Int.getBitWidth() == 32); | |
| 28 union { | |
| 29 uint32_t IntValue; | |
| 30 float FloatValue; | |
| 31 } Converter; | |
| 32 Converter.IntValue = static_cast<uint32_t>(Int.getRawData()); | |
| 33 return Converter.FloatValue; | |
| 34 } | |
| 35 | |
| 36 /// Takes a 64-bit Int and converts it to the corresponding double value. | |
|
Jim Stichnoth
2014/12/12 21:54:15
Consider reducing code duplication:
template<type
Karl
2014/12/12 22:46:12
Done.
| |
| 37 inline double convertAPIntToDouble(const APInt &Int) { | |
| 38 assert(Int.getBitWidth() == 64); | |
| 39 union { | |
| 40 uint64_t IntValue; | |
| 41 double DoubleValue; | |
| 42 } Converter; | |
| 43 Converter.IntValue = static_cast<uint64_t>(Int.getRawData()); | |
| 44 return Converter.DoubleValue; | |
| 45 } | |
| 46 | |
| 47 } // end of namespace Ice | |
| 48 | |
| 49 #endif // SUBZERO_SRC_ICEAPFLOAT_H | |
| OLD | NEW |