Geant4  10.02.p03
CLHEP::DoubConv Class Reference

#include <DoubConv.h>

Collaboration diagram for CLHEP::DoubConv:

Classes

union  DB8
 

Static Public Member Functions

static std::vector< unsigned long > dto2longs (double d)
 
static double longs2double (const std::vector< unsigned long > &v)
 
static std::string d2x (double d)
 

Static Private Member Functions

static void fill_byte_order ()
 

Static Private Attributes

static CLHEP_THREAD_LOCAL bool byte_order_known = false
 
static CLHEP_THREAD_LOCAL int byte_order [8]
 

Detailed Description

Definition at line 29 of file DoubConv.h.

Member Function Documentation

◆ d2x()

std::string CLHEP::DoubConv::d2x ( double  d)
static

Definition at line 86 of file DoubConv.cc.

86  {
88  DB8 db;
89  db.d = d;
90  std::ostringstream ss;
91  for (int i=0; i<8; ++i) {
92  int k = byte_order[i];
93  ss << std::hex << std::setw(2) << std::setfill('0') << (int)db.b[k];
94  }
95  return ss.str();
96 }
Float_t d
static CLHEP_THREAD_LOCAL int byte_order[8]
Definition: DoubConv.h:61
static CLHEP_THREAD_LOCAL bool byte_order_known
Definition: DoubConv.h:60
static void fill_byte_order()
Definition: DoubConv.cc:19
Here is the call graph for this function:

◆ dto2longs()

std::vector< unsigned long > CLHEP::DoubConv::dto2longs ( double  d)
static

Definition at line 98 of file DoubConv.cc.

98  {
99  std::vector<unsigned long> v(2);
101  DB8 db;
102  db.d = d;
103  v[0] = ((static_cast<unsigned long>(db.b[byte_order[0]])) << 24)
104  | ((static_cast<unsigned long>(db.b[byte_order[1]])) << 16)
105  | ((static_cast<unsigned long>(db.b[byte_order[2]])) << 8)
106  | ((static_cast<unsigned long>(db.b[byte_order[3]])) );
107  v[1] = ((static_cast<unsigned long>(db.b[byte_order[4]])) << 24)
108  | ((static_cast<unsigned long>(db.b[byte_order[5]])) << 16)
109  | ((static_cast<unsigned long>(db.b[byte_order[6]])) << 8)
110  | ((static_cast<unsigned long>(db.b[byte_order[7]])) );
111  return v;
112 }
Float_t d
static CLHEP_THREAD_LOCAL int byte_order[8]
Definition: DoubConv.h:61
static CLHEP_THREAD_LOCAL bool byte_order_known
Definition: DoubConv.h:60
static void fill_byte_order()
Definition: DoubConv.cc:19
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fill_byte_order()

void CLHEP::DoubConv::fill_byte_order ( )
staticprivate

Definition at line 19 of file DoubConv.cc.

19  {
20  double x = 1.0;
21  int t30 = 1 << 30;
22  int t22 = 1 << 22;
23  x *= t30;
24  x *= t22;
25  double y = 1;
26  double z = 1;
27  x *= z;
28  for (int k=0; k<6; k++) {
29  x += y*z;
30  y += 1;
31  z *= 256;
32  }
33  // x, in IEEE format, would now be 0x4330060504030201
34  union DB8 {
35  unsigned char b[8];
36  double d;
37  };
38  DB8 xb;
39  xb.d = x;
40  int n;
41  static const int UNSET = -1;
42  for (n=0; n<8; n++) {
43  byte_order[n] = UNSET;
44  }
45  int order;
46  for (n=0; n<8; n++) {
47  switch ( xb.b[n] ) {
48  case 0x43:
49  order = 0;
50  break;
51  case 0x30:
52  order = 1;
53  break;
54  case 0x06:
55  order = 2;
56  break;
57  case 0x05:
58  order = 3;
59  break;
60  case 0x04:
61  order = 4;
62  break;
63  case 0x03:
64  order = 5;
65  break;
66  case 0x02:
67  order = 6;
68  break;
69  case 0x01:
70  order = 7;
71  break;
72  default:
73  throw DoubConvException(
74  "Cannot determine byte-ordering of doubles on this system");
75  }
76  if (byte_order[n] != UNSET) {
77  throw DoubConvException(
78  "Confusion in byte-ordering of doubles on this system");
79  }
80  byte_order[n] = order;
81  byte_order_known = true;
82  }
83  return;
84 }
Double_t y
Char_t n[5]
static CLHEP_THREAD_LOCAL int byte_order[8]
Definition: DoubConv.h:61
unsigned char b[8]
Definition: DoubConv.h:56
static CLHEP_THREAD_LOCAL bool byte_order_known
Definition: DoubConv.h:60
Here is the caller graph for this function:

◆ longs2double()

double CLHEP::DoubConv::longs2double ( const std::vector< unsigned long > &  v)
static

Definition at line 114 of file DoubConv.cc.

114  {
115  DB8 db;
116  unsigned char bytes[8];
118  bytes[0] = static_cast<unsigned char>((v[0] >> 24) & 0xFF);
119  bytes[1] = static_cast<unsigned char>((v[0] >> 16) & 0xFF);
120  bytes[2] = static_cast<unsigned char>((v[0] >> 8) & 0xFF);
121  bytes[3] = static_cast<unsigned char>((v[0] ) & 0xFF);
122  bytes[4] = static_cast<unsigned char>((v[1] >> 24) & 0xFF);
123  bytes[5] = static_cast<unsigned char>((v[1] >> 16) & 0xFF);
124  bytes[6] = static_cast<unsigned char>((v[1] >> 8) & 0xFF);
125  bytes[7] = static_cast<unsigned char>((v[1] ) & 0xFF);
126  for (int i=0; i<8; ++i) {
127  db.b[byte_order[i]] = bytes[i];
128  }
129  return db.d;
130 }
static CLHEP_THREAD_LOCAL int byte_order[8]
Definition: DoubConv.h:61
static CLHEP_THREAD_LOCAL bool byte_order_known
Definition: DoubConv.h:60
static void fill_byte_order()
Definition: DoubConv.cc:19
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ byte_order

CLHEP_THREAD_LOCAL int CLHEP::DoubConv::byte_order
staticprivate

Definition at line 61 of file DoubConv.h.

◆ byte_order_known

CLHEP_THREAD_LOCAL bool CLHEP::DoubConv::byte_order_known = false
staticprivate

Definition at line 60 of file DoubConv.h.


The documentation for this class was generated from the following files: