Geant4_10
DoubConv.h
Go to the documentation of this file.
1 // $Id:$
2 // -*- C++ -*-
3 //
4 // -----------------------------------------------------------------------
5 // Hep Random
6 // --- DoubConv ---
7 // class header file
8 // -----------------------------------------------------------------------
9 //
10 #ifndef DOUBCONV_HH
11 #define DOUBCONV_HH
12 
13 #include <string>
14 #include <vector>
15 #include <exception>
16 
17 namespace CLHEP {
18 
19 class DoubConvException : public std::exception {
20 public:
21  DoubConvException(const std::string & w) throw() : msg(w) {}
22  ~DoubConvException() throw() {}
23  const char* what() const throw() { return msg.c_str(); }
24 private:
25  std::string msg;
26 };
27 
28 class DoubConv {
29 public:
30 
31  // dto2longs(d) returns (in a vector) two unsigned longs string containing the
32  // representation of its double input. This is byte-ordering
33  // independant, and depends for complete portability ONLY on adherance
34  // to the IEEE 754 standard for 64-bit floating point representation.
35  // The first unsigned long contains the high-order bits in IEEE; thus
36  // 1.0 will always be 0x3FF00000, 00000000
37  static std::vector<unsigned long> dto2longs(double d);
38 
39  // longs2double (v) returns a double containing the value represented by its
40  // input, which must be a vector containing 2 unsigned longs.
41  // The input is taken to be the representation according to
42  // the IEEE 754 standard for a 64-bit floating point number, whose value
43  // is returned as a double. The byte-ordering of the double result is,
44  // of course, tailored to the proper byte-ordering for the system.
45  static double longs2double (const std::vector<unsigned long> & v);
46 
47  // dtox(d) returns a 16-character string containing the (zero-filled) hex
48  // representation of its double input. This is byte-ordering
49  // independant, and depends for complete portability ONLY on adherance
50  // to the IEEE 754 standard for 64-bit floating point representation.
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 bool byte_order_known;
60  static int byte_order[8];
61  // Meaning of byte_order: The first (high-order in IEEE 754) byte to
62  // output (or the high-order byte of the first unsigned long)
63  // is of db.b[byte_order[0]]. Thus the index INTO byte_order
64  // is a position in the IEEE representation of the double, and the value
65  // of byte_order[k] is an offset in the memory representation of the
66  // double.
67 };
68 
69 
70 }
71 
72 #endif // DOUBCONV_HH
Float_t d
Definition: plot.C:237
const char * what() const
Definition: DoubConv.h:23
DoubConvException(const std::string &w)
Definition: DoubConv.h:21
tuple b
Definition: test.py:12
static std::string d2x(double d)
Definition: DoubConv.cc:86
tuple v
Definition: test.py:18
static std::vector< unsigned long > dto2longs(double d)
Definition: DoubConv.cc:98
static double longs2double(const std::vector< unsigned long > &v)
Definition: DoubConv.cc:114