12 namespace GenVector_detail {
14 bool BitReproducible::fgByte_order_known =
false;
15 int BitReproducible::fgByte_order[8];
17 void BitReproducible::Fill_byte_order () {
27 for (
int k=0; k<6; k++) {
36 static const int kUNSET = -1;
38 fgByte_order[n] = kUNSET;
68 throw BitReproducibleException(
69 "Cannot determine byte-ordering of doubles on this system");
71 if (fgByte_order[n] != kUNSET) {
72 throw BitReproducibleException(
73 "Confusion in byte-ordering of doubles on this system");
75 fgByte_order[n] = order;
76 fgByte_order_known =
true;
81 std::string BitReproducible::D2x(
double d) {
83 if ( !fgByte_order_known ) Fill_byte_order ();
86 std::ostringstream ss;
87 for (
int i=0; i<8; ++i) {
88 int k = fgByte_order[i];
89 ss << std::hex << std::setw(2) << std::setfill(
'0') << (int)db.fB[k];
94 void BitReproducible::Dto2longs(
double d,
unsigned int& i,
unsigned int& j) {
96 if ( !fgByte_order_known ) Fill_byte_order ();
99 i = ((
static_cast<unsigned int>(db.fB[fgByte_order[0]])) << 24)
100 | ((static_cast<unsigned int>(db.fB[fgByte_order[1]])) << 16)
101 | ((
static_cast<unsigned int>(db.fB[fgByte_order[2]])) << 8)
102 | ((static_cast<unsigned int>(db.fB[fgByte_order[3]])) );
103 j = ((
static_cast<unsigned int>(db.fB[fgByte_order[4]])) << 24)
104 | ((static_cast<unsigned int>(db.fB[fgByte_order[5]])) << 16)
105 | ((
static_cast<unsigned int>(db.fB[fgByte_order[6]])) << 8)
106 | ((static_cast<unsigned int>(db.fB[fgByte_order[7]])) );
109 double BitReproducible::Longs2double (
unsigned int i,
unsigned int j) {
112 unsigned char bytes[8];
113 if ( !fgByte_order_known ) Fill_byte_order ();
114 bytes[0] =
static_cast<unsigned char>((i >> 24) & 0xFF);
115 bytes[1] =
static_cast<unsigned char>((i >> 16) & 0xFF);
116 bytes[2] =
static_cast<unsigned char>((i >> 8) & 0xFF);
117 bytes[3] =
static_cast<unsigned char>((i ) & 0xFF);
118 bytes[4] =
static_cast<unsigned char>((j >> 24) & 0xFF);
119 bytes[5] =
static_cast<unsigned char>((j >> 16) & 0xFF);
120 bytes[6] =
static_cast<unsigned char>((j >> 8) & 0xFF);
121 bytes[7] =
static_cast<unsigned char>((j ) & 0xFF);
122 for (
int k=0; k<8; ++k) {
123 db.fB[fgByte_order[k]] = bytes[k];