Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
BitReproducible.cxx
Go to the documentation of this file.
1// @(#)root/mathcore:$Id$
2// Authors: W. Brown, M. Fischler, L. Moneta 2005
3
5
6#include <sstream>
7#include <iomanip>
8#include <exception>
9
11
13
14#if !defined(ROOT_MATH_SYCL) && !defined(ROOT_MATH_CUDA)
15
16namespace ROOT {
17namespace ROOT_MATH_ARCH {
18namespace GenVector_detail {
19
22
24{
25 // Fill_byte_order
26 double x = 1.0;
27 int t30 = 1 << 30;
28 int t22 = 1 << 22;
29 x *= t30;
30 x *= t22;
31 double y = 1;
32 double z = 1;
33 x *= z;
34 for (int k = 0; k < 6; k++) {
35 x += y * z;
36 y += 1;
37 z *= 256;
38 }
39 // x, in IEEE format, would now be 0x4330060504030201
40 DB8 xb;
41 xb.fD = x;
42 int n;
43 static const int kUNSET = -1;
44 for (n = 0; n < 8; n++) {
46 }
47 int order;
48 for (n = 0; n < 8; n++) {
49 switch (xb.fB[n]) {
50 case 0x43: order = 0; break;
51 case 0x30: order = 1; break;
52 case 0x06: order = 2; break;
53 case 0x05: order = 3; break;
54 case 0x04: order = 4; break;
55 case 0x03: order = 5; break;
56 case 0x02: order = 6; break;
57 case 0x01: order = 7; break;
58 default: throw BitReproducibleException("Cannot determine byte-ordering of doubles on this system");
59 }
60 if (fgByte_order[n] != kUNSET) {
61 throw BitReproducibleException("Confusion in byte-ordering of doubles on this system");
62 }
63 fgByte_order[n] = order;
64 fgByte_order_known = true;
65 }
66 return;
67}
68
69#if !defined(ROOT_MATH_SYCL) && !defined(ROOT_MATH_CUDA)
70std::string BitReproducible::D2x(double d)
71{
72 // hex conversion
75 DB8 db;
76 db.fD = d;
77 std::ostringstream ss;
78 for (int i = 0; i < 8; ++i) {
79 int k = fgByte_order[i];
80 ss << std::hex << std::setw(2) << std::setfill('0') << (int)db.fB[k];
81 }
82 return ss.str();
83}
84#endif
85
86void BitReproducible::Dto2longs(double d, unsigned int &i, unsigned int &j)
87{
88 // conversion to 2 longs
91 DB8 db;
92 db.fD = d;
93 i = ((static_cast<unsigned int>(db.fB[fgByte_order[0]])) << 24) |
94 ((static_cast<unsigned int>(db.fB[fgByte_order[1]])) << 16) |
95 ((static_cast<unsigned int>(db.fB[fgByte_order[2]])) << 8) |
96 ((static_cast<unsigned int>(db.fB[fgByte_order[3]])));
97 j = ((static_cast<unsigned int>(db.fB[fgByte_order[4]])) << 24) |
98 ((static_cast<unsigned int>(db.fB[fgByte_order[5]])) << 16) |
99 ((static_cast<unsigned int>(db.fB[fgByte_order[6]])) << 8) |
100 ((static_cast<unsigned int>(db.fB[fgByte_order[7]])));
101}
102
103double BitReproducible::Longs2double(unsigned int i, unsigned int j)
104{
105 // conversion longs to double
106 DB8 db;
107 unsigned char bytes[8];
110 bytes[0] = static_cast<unsigned char>((i >> 24) & 0xFF);
111 bytes[1] = static_cast<unsigned char>((i >> 16) & 0xFF);
112 bytes[2] = static_cast<unsigned char>((i >> 8) & 0xFF);
113 bytes[3] = static_cast<unsigned char>((i) & 0xFF);
114 bytes[4] = static_cast<unsigned char>((j >> 24) & 0xFF);
115 bytes[5] = static_cast<unsigned char>((j >> 16) & 0xFF);
116 bytes[6] = static_cast<unsigned char>((j >> 8) & 0xFF);
117 bytes[7] = static_cast<unsigned char>((j) & 0xFF);
118 for (int k = 0; k < 8; ++k) {
119 db.fB[fgByte_order[k]] = bytes[k];
120 }
121 return db.fD;
122}
123
124} // namespace GenVector_detail
125} // namespace ROOT_MATH_ARCH
126} // namespace ROOT
127
128#endif
#define d(i)
Definition RSha256.hxx:102
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t bytes
static double Longs2double(unsigned int i1, unsigned int i2)
static void Dto2longs(double d, unsigned int &i1, unsigned int &i2)
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16