Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/Geant4/G4IEEE754.hh was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 #ifndef G4IEEE754_hh
0027 #define G4IEEE754_hh 1
0028 
0029 #include "G4Types.hh"
0030 
0031 #include <cstdint>
0032 
0033 namespace G4IEEE754
0034 {
0035 //----------------------------------------------------------------------------
0036 // Used to switch between different type of interpretations of the data
0037 // (64 bits)
0038 //
0039 union ieee754
0040 {
0041     ieee754() = default;
0042     ieee754(G4double thed) { d = thed; };
0043     ieee754(uint64_t thell) { ll = thell; };
0044     ieee754(G4float thef) { f[0] = thef; };
0045     ieee754(uint32_t thei) { i[0] = thei; };
0046     G4double d;
0047     G4float f[2];
0048     uint32_t i[2];
0049     uint64_t ll;
0050     uint16_t s[4];
0051 };
0052 
0053 //----------------------------------------------------------------------------
0054 // Converts a double to an unsigned long long
0055 //
0056 inline uint64_t dp2uint64(G4double x)
0057 {
0058   ieee754 tmp;
0059   tmp.d = x;
0060   return tmp.ll;
0061 }
0062 
0063 //----------------------------------------------------------------------------
0064 // Converts an unsigned long long to a double
0065 //
0066 inline G4double uint642dp(uint64_t ll)
0067 {
0068   ieee754 tmp;
0069   tmp.ll = ll;
0070   return tmp.d;
0071 }
0072 
0073 //----------------------------------------------------------------------------
0074 // Converts an int to a float
0075 //
0076 inline G4float uint322sp(G4int x)
0077 {
0078   ieee754 tmp;
0079   tmp.i[0] = x;
0080   return tmp.f[0];
0081 }
0082 
0083 //----------------------------------------------------------------------------
0084 // Converts a float to an int
0085 //
0086 inline uint32_t sp2uint32(G4float x)
0087 {
0088   ieee754 tmp;
0089   tmp.f[0] = x;
0090   return tmp.i[0];
0091 }
0092 }  // namespace G4IEEE754
0093 
0094 #endif