Geant4 Cross Reference |
1 // -*- C++ -*- 1 2 // 3 // ------------------------------------------- 4 // Hep Random 5 // --- DoubConv --- 6 // class header file 7 // ------------------------------------------- 8 // 9 #ifndef DOUBCONV_HH 10 #define DOUBCONV_HH 11 12 #include <string> 13 #include <vector> 14 #include <exception> 15 #include "CLHEP/Utility/thread_local.h" 16 17 namespace CLHEP { 18 19 class DoubConvException : public std::excepti 20 public: 21 DoubConvException(const std::string & w) thr 22 ~DoubConvException() throw() {} 23 const char* what() const throw() { return ms 24 private: 25 std::string msg; 26 }; 27 28 class DoubConv { 29 public: 30 31 // dto2longs(d) returns (in a vector) two un 32 // representation of its double input. This 33 // independant, and depends for complete por 34 // to the IEEE 754 standard for 64-bit float 35 // The first unsigned long contains the high 36 // 1.0 will always be 0x3FF00000, 00000000 37 static std::vector<unsigned long> dto2longs( 38 39 // longs2double (v) returns a double contain 40 // input, which must be a vector containing 41 // The input is taken to be the representati 42 // the IEEE 754 standard for a 64-bit floati 43 // is returned as a double. The byte-orderi 44 // of course, tailored to the proper byte-or 45 static double longs2double (const std::vecto 46 47 // dtox(d) returns a 16-character string con 48 // representation of its double input. This 49 // independant, and depends for complete por 50 // to the IEEE 754 standard for 64-bit float 51 static std::string d2x(double d); 52 53 private: 54 union DB8 { 55 unsigned char b[8]; 56 double d; 57 }; 58 static void fill_byte_order (); 59 static CLHEP_THREAD_LOCAL bool byte_order_kn 60 static CLHEP_THREAD_LOCAL int byte_order[8] 61 // Meaning of byte_order: The first (high 62 // output (or the high-order byte of the f 63 // is of db.b[byte_order[0]]. Thus the i 64 // is a position in the IEEE representatio 65 // of byte_order[k] is an offset in the me 66 // double. 67 }; 68 69 70 } 71 72 #endif // DOUBCONV_HH 73