1#include "CLHEP/Random/DoubConv.hh"
8bool DoubConv::byte_order_known =
false;
9int DoubConv::byte_order[8];
11void DoubConv::fill_byte_order () {
20 for (
int k=0; k<6; k++) {
33 static const int UNSET = -1;
35 byte_order[
n] = UNSET;
65 throw DoubConvException(
66 "Cannot determine byte-ordering of doubles on this system");
68 if (byte_order[
n] != UNSET) {
69 throw DoubConvException(
70 "Confusion in byte-ordering of doubles on this system");
72 byte_order[
n] = order;
73 byte_order_known =
true;
79 if ( !byte_order_known ) fill_byte_order ();
82 std::ostringstream ss;
83 for (
int i=0; i<8; ++i) {
84 int k = byte_order[i];
85 ss << std::hex << std::setw(2) << std::setfill(
'0') << (int)db.b[k];
91 std::vector<unsigned long> v(2);
92 if ( !byte_order_known ) fill_byte_order ();
95 v[0] = ((
static_cast<unsigned long>(db.b[byte_order[0]])) << 24)
96 | ((
static_cast<unsigned long>(db.b[byte_order[1]])) << 16)
97 | ((
static_cast<unsigned long>(db.b[byte_order[2]])) << 8)
98 | ((
static_cast<unsigned long>(db.b[byte_order[3]])) );
99 v[1] = ((
static_cast<unsigned long>(db.b[byte_order[4]])) << 24)
100 | ((
static_cast<unsigned long>(db.b[byte_order[5]])) << 16)
101 | ((
static_cast<unsigned long>(db.b[byte_order[6]])) << 8)
102 | ((
static_cast<unsigned long>(db.b[byte_order[7]])) );
108 unsigned char bytes[8];
109 if ( !byte_order_known ) fill_byte_order ();
110 bytes[0] =
static_cast<unsigned char>((v[0] >> 24) & 0xFF);
111 bytes[1] =
static_cast<unsigned char>((v[0] >> 16) & 0xFF);
112 bytes[2] =
static_cast<unsigned char>((v[0] >> 8) & 0xFF);
113 bytes[3] =
static_cast<unsigned char>((v[0] ) & 0xFF);
114 bytes[4] =
static_cast<unsigned char>((v[1] >> 24) & 0xFF);
115 bytes[5] =
static_cast<unsigned char>((v[1] >> 16) & 0xFF);
116 bytes[6] =
static_cast<unsigned char>((v[1] >> 8) & 0xFF);
117 bytes[7] =
static_cast<unsigned char>((v[1] ) & 0xFF);
118 for (
int i=0; i<8; ++i) {
119 db.b[byte_order[i]] = bytes[i];
static double longs2double(const std::vector< unsigned long > &v)
static std::vector< unsigned long > dto2longs(double d)
static std::string d2x(double d)