Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // Module defining platform dependent features << 26 // >> 27 // $Id: templates.hh 103661 2017-04-20 14:57:11Z gcosmo $ >> 28 // >> 29 // >> 30 // -*- C++ -*- >> 31 // >> 32 // ----------------------------------------------------------------------- >> 33 // This file should define some platform dependent features and some >> 34 // useful utilities. >> 35 // ----------------------------------------------------------------------- >> 36 >> 37 // ======================================================================= >> 38 // Gabriele Cosmo - Created: 5th September 1995 >> 39 // Gabriele Cosmo - Minor change: 08/02/1996 >> 40 // Gabriele Cosmo - Added DBL_MIN, FLT_MIN, DBL_DIG, >> 41 // DBL_MAX, FLT_DIG, FLT_MAX : 12/04/1996 >> 42 // Gabriele Cosmo - Removed boolean enum definition : 29/11/1996 >> 43 // Gunter Folger - Added G4SwapPtr() and G4SwapObj() : 31/07/1997 >> 44 // Gabriele Cosmo - Adapted signatures of min(), max() to >> 45 // STL's ones, thanks to E.Tcherniaev : 31/07/1997 >> 46 // Gabriele Cosmo, >> 47 // Evgueni Tcherniaev - Migrated to CLHEP: 04/12/1997 >> 48 // ======================================================================= 27 49 28 // Author: Gabriele Cosmo, 5 September 1995 - << 50 #ifndef templates_h 29 // ------------------------------------------- << 51 #define templates_h 1 30 #ifndef templates_hh << 31 #define templates_hh 1 << 32 52 33 #include <climits> << 34 #include <limits> 53 #include <limits> >> 54 #include <climits> 35 55 >> 56 // 36 // If HIGH_PRECISION is defined to TRUE (ie. ! 57 // If HIGH_PRECISION is defined to TRUE (ie. != 0) then the type "Float" 37 // is typedefed to "double". If it is FALSE (i 58 // is typedefed to "double". If it is FALSE (ie. 0) it is typedefed 38 // to "float". 59 // to "float". 39 // 60 // 40 #ifndef HIGH_PRECISION 61 #ifndef HIGH_PRECISION 41 # define HIGH_PRECISION 1 << 62 #define HIGH_PRECISION 1 42 #endif 63 #endif 43 64 44 #if HIGH_PRECISION 65 #if HIGH_PRECISION 45 using Float = double; << 66 typedef double Float; 46 #else 67 #else 47 using Float = float; << 68 typedef float Float; 48 #endif 69 #endif 49 70 50 // Following values have been taken from limit 71 // Following values have been taken from limits.h 51 // and temporarly defined for portability on H 72 // and temporarly defined for portability on HP-UX. 52 73 53 #ifndef DBL_MIN /* Min decimal value of a doub << 74 #ifndef DBL_MIN /* Min decimal value of a double */ 54 # define DBL_MIN std::numeric_limits<double>: << 75 #define DBL_MIN std::numeric_limits<double>::min() // 2.2250738585072014e-308 55 #endif 76 #endif 56 77 57 #ifndef DBL_DIG /* Digits of precision of a do << 78 #ifndef DBL_DIG /* Digits of precision of a double */ 58 # define DBL_DIG std::numeric_limits<double>: << 79 #define DBL_DIG std::numeric_limits<double>::digits10 // 15 59 #endif 80 #endif 60 81 61 #ifndef DBL_MAX /* Max decimal value of a doub << 82 #ifndef DBL_MAX /* Max decimal value of a double */ 62 # define DBL_MAX std::numeric_limits<double>: << 83 #define DBL_MAX std::numeric_limits<double>::max() // 1.7976931348623157e+308 63 #endif 84 #endif 64 85 65 #ifndef DBL_EPSILON 86 #ifndef DBL_EPSILON 66 # define DBL_EPSILON std::numeric_limits<doub << 87 #define DBL_EPSILON std::numeric_limits<double>::epsilon() 67 #endif // 2.2204460492503131e-16 << 88 #endif // 2.2204460492503131e-16 68 89 69 #ifndef FLT_MIN /* Min decimal value of a floa << 90 #ifndef FLT_MIN /* Min decimal value of a float */ 70 # define FLT_MIN std::numeric_limits<float>:: << 91 #define FLT_MIN std::numeric_limits<float>::min() // 1.17549435e-38F 71 #endif 92 #endif 72 93 73 #ifndef FLT_DIG /* Digits of precision of a fl << 94 #ifndef FLT_DIG /* Digits of precision of a float */ 74 # define FLT_DIG std::numeric_limits<float>:: << 95 #define FLT_DIG std::numeric_limits<float>::digits10 // 6 75 #endif 96 #endif 76 97 77 #ifndef FLT_MAX /* Max decimal value of a floa << 98 #ifndef FLT_MAX /* Max decimal value of a float */ 78 # define FLT_MAX std::numeric_limits<float>:: << 99 #define FLT_MAX std::numeric_limits<float>::max() // 3.40282347e+38F 79 #endif 100 #endif 80 101 81 #ifndef FLT_EPSILON 102 #ifndef FLT_EPSILON 82 # define FLT_EPSILON std::numeric_limits<floa << 103 #define FLT_EPSILON std::numeric_limits<float>::epsilon() 83 #endif // 1.192092896e-07F << 104 #endif // 1.192092896e-07F 84 << 85 #ifndef MAXFLOAT /* Max decimal value of a flo << 86 # define MAXFLOAT std::numeric_limits<float>: << 87 #endif << 88 105 89 #ifndef INT_MAX /* Max decimal value of a int << 106 #ifndef MAXFLOAT /* Max decimal value of a float */ 90 # define INT_MAX std::numeric_limits<int>::ma << 107 #define MAXFLOAT std::numeric_limits<float>::max() // 3.40282347e+38F 91 #endif 108 #endif 92 109 93 #ifndef INT_MIN /* Min decimal value of a int << 110 #ifndef INT_MAX /* Max decimal value of a int */ 94 # define INT_MIN std::numeric_limits<int>::mi << 111 #define INT_MAX std::numeric_limits<int>::max() // 2147483647 95 #endif 112 #endif 96 113 97 #ifndef LOG_EKIN_MIN /* Min value of the natur << 114 #ifndef INT_MIN /* Min decimal value of a int */ 98 # define LOG_EKIN_MIN -30 << 115 #define INT_MIN std::numeric_limits<int>::min() // -2147483648 99 #endif 116 #endif 100 117 101 //--------------------------------- 118 //--------------------------------- 102 119 103 template <class T> 120 template <class T> 104 inline void G4SwapPtr(T*& a, T*& b) 121 inline void G4SwapPtr(T*& a, T*& b) 105 { 122 { 106 T* tmp = a; << 123 T* tmp= a; 107 a = b; << 124 a = b; 108 b = tmp; << 125 b = tmp; 109 } 126 } 110 127 111 template <class T> 128 template <class T> 112 inline void G4SwapObj(T* a, T* b) 129 inline void G4SwapObj(T* a, T* b) 113 { 130 { 114 T tmp = *a; << 131 T tmp= *a; 115 *a = *b; << 132 *a = *b; 116 *b = tmp; << 133 *b = tmp; 117 } 134 } 118 135 119 //----------------------------- 136 //----------------------------- 120 137 121 #ifndef G4_SQR_DEFINED 138 #ifndef G4_SQR_DEFINED 122 # define G4_SQR_DEFINED << 139 #define G4_SQR_DEFINED 123 # ifdef sqr << 140 #ifdef sqr 124 # undef sqr << 141 #undef sqr 125 # endif << 142 #endif 126 143 127 template <class T> 144 template <class T> 128 inline T sqr(const T& x) 145 inline T sqr(const T& x) 129 { 146 { 130 return x * x; << 147 return x*x; 131 } 148 } 132 #endif 149 #endif 133 150 134 inline int G4lrint(double ad) 151 inline int G4lrint(double ad) 135 { 152 { 136 return (int)std::lrint(ad); << 153 return (ad>0) ? static_cast<int>(ad+.5) : static_cast<int>(ad-.5); 137 } 154 } 138 155 139 //----------------------------- << 156 inline int G4lint(double ad) >> 157 { >> 158 return (ad>0) ? static_cast<int>(ad) : static_cast<int>(ad-1.); >> 159 } 140 160 141 // Use the following function to get rid of " << 161 inline int G4rint(double ad) 142 // Example: << 162 { 143 // << 163 return (ad>0) ? static_cast<int>(ad+1) : static_cast<int>(ad); 144 // #ifdef SOME_CONDITION << 164 } 145 // void doSomething(int val) << 146 // { << 147 // something = val; << 148 // } << 149 // #else << 150 // void doSomething(int) << 151 // { } << 152 // #endif << 153 // << 154 // can be simplified to: << 155 // << 156 // void doSomething(int val) << 157 // { << 158 // #ifdef SOME_CONDITION << 159 // something = val; << 160 // #else << 161 // G4ConsumeParameters(val); << 162 // #endif << 163 // } << 164 // << 165 // or: << 166 // << 167 // void doSomething(int val) << 168 // { << 169 // #ifdef SOME_CONDITION << 170 // something = val; << 171 // #endif << 172 // // function call does nothing << 173 // G4ConsumeParameters(val); << 174 // } << 175 // << 176 template <typename... _Args> << 177 inline void G4ConsumeParameters(_Args&&...) << 178 {} << 179 165 180 #endif // templates_hh << 166 #endif // templates_h 181 167