Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:03:28

0001 // -*- C++ -*-

0002 //

0003 // -----------------------------------------------------------------------

0004 //                           Hep Random

0005 //                        --- DoubConv ---

0006 //                        class header file

0007 // -----------------------------------------------------------------------

0008 //                                                                      

0009 #ifndef DOUBCONV_H
0010 #define DOUBCONV_H
0011 
0012 #include <string>
0013 #include <vector>
0014 #include <exception>
0015 #include "CLHEP/Utility/thread_local.h"
0016 
0017 namespace CLHEP {
0018 
0019 class DoubConvException  : public std::exception {
0020 public:
0021   DoubConvException(const std::string & w) throw() : msg(w) {}
0022   ~DoubConvException() throw() {}
0023   const char* what() const throw() { return msg.c_str(); }
0024 private:
0025   std::string msg;
0026 };
0027 
0028 class DoubConv {
0029 public:
0030 
0031   // dto2longs(d) returns (in a vector) two unsigned longs string containing the

0032   // representation of its double input.  This is byte-ordering 

0033   // independant, and depends for complete portability ONLY on adherance 

0034   // to the IEEE 754 standard for 64-bit floating point representation.

0035   // The first unsigned long contains the high-order bits in IEEE; thus

0036   // 1.0 will always be 0x3FF00000, 00000000

0037   static std::vector<unsigned long> dto2longs(double d);
0038 
0039   // longs2double (v) returns a double containing the value represented by its  

0040   // input, which must be a vector containing 2 unsigned longs.  

0041   // The input is taken to be the representation according to

0042   // the IEEE 754 standard for a 64-bit floating point number, whose value

0043   // is returned as a double.  The byte-ordering of the double result is, 

0044   // of course, tailored to the proper byte-ordering for the system.

0045   static double longs2double (const std::vector<unsigned long> & v);
0046 
0047   // dtox(d) returns a 16-character string containing the (zero-filled) hex 

0048   // representation of its double input.  This is byte-ordering 

0049   // independant, and depends for complete portability ONLY on adherance 

0050   // to the IEEE 754 standard for 64-bit floating point representation.

0051   static std::string d2x(double d);
0052  
0053 private:
0054   union DB8 {
0055     unsigned char b[8];
0056     double d;
0057   };
0058   static void fill_byte_order ();
0059   static CLHEP_THREAD_LOCAL bool byte_order_known;
0060   static CLHEP_THREAD_LOCAL int  byte_order[8];
0061     // Meaning of byte_order:  The first (high-order in IEEE 754) byte to

0062     // output (or the high-order byte of the first unsigned long)

0063     // is  of db.b[byte_order[0]].  Thus the index INTO byte_order

0064     // is a position in the IEEE representation of the double, and the value

0065     // of byte_order[k] is an offset in the memory representation of the 

0066     // double.  

0067 };
0068 
0069 
0070 }
0071 
0072 #endif // DOUBCONV_H