Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4IEEE754.hh
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26#ifndef G4IEEE754_hh
27#define G4IEEE754_hh 1
28
29#include "G4Types.hh"
30
31#include <cstdint>
32
33namespace G4IEEE754
34{
35//----------------------------------------------------------------------------
36// Used to switch between different type of interpretations of the data
37// (64 bits)
38//
40{
41 ieee754() = default;
42 ieee754(G4double thed) { d = thed; };
43 ieee754(uint64_t thell) { ll = thell; };
44 ieee754(G4float thef) { f[0] = thef; };
45 ieee754(uint32_t thei) { i[0] = thei; };
48 uint32_t i[2];
49 uint64_t ll;
50 uint16_t s[4];
51};
52
53//----------------------------------------------------------------------------
54// Converts a double to an unsigned long long
55//
56inline uint64_t dp2uint64(G4double x)
57{
58 ieee754 tmp;
59 tmp.d = x;
60 return tmp.ll;
61}
62
63//----------------------------------------------------------------------------
64// Converts an unsigned long long to a double
65//
66inline G4double uint642dp(uint64_t ll)
67{
68 ieee754 tmp;
69 tmp.ll = ll;
70 return tmp.d;
71}
72
73//----------------------------------------------------------------------------
74// Converts an int to a float
75//
77{
78 ieee754 tmp;
79 tmp.i[0] = x;
80 return tmp.f[0];
81}
82
83//----------------------------------------------------------------------------
84// Converts a float to an int
85//
86inline uint32_t sp2uint32(G4float x)
87{
88 ieee754 tmp;
89 tmp.f[0] = x;
90 return tmp.i[0];
91}
92} // namespace G4IEEE754
93
94#endif
float G4float
Definition G4Types.hh:84
double G4double
Definition G4Types.hh:83
int G4int
Definition G4Types.hh:85
G4double uint642dp(uint64_t ll)
Definition G4IEEE754.hh:66
uint32_t sp2uint32(G4float x)
Definition G4IEEE754.hh:86
uint64_t dp2uint64(G4double x)
Definition G4IEEE754.hh:56
G4float uint322sp(G4int x)
Definition G4IEEE754.hh:76
ieee754(G4float thef)
Definition G4IEEE754.hh:44
ieee754(uint32_t thei)
Definition G4IEEE754.hh:45
ieee754(uint64_t thell)
Definition G4IEEE754.hh:43
ieee754(G4double thed)
Definition G4IEEE754.hh:42
uint32_t i[2]
Definition G4IEEE754.hh:48
uint16_t s[4]
Definition G4IEEE754.hh:50