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 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  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 // Module defining platform dependent features and some useful utilities.
 27 
 28 // Author: Gabriele Cosmo, 5 September 1995 - Created
 29 // --------------------------------------------------------------------
 30 #ifndef templates_hh
 31 #define templates_hh 1
 32 
 33 #include <climits>
 34 #include <limits>
 35 
 36 // If HIGH_PRECISION is defined to TRUE (ie. != 0) then the type "Float"
 37 // is typedefed to "double". If it is FALSE (ie. 0) it is typedefed
 38 // to "float".
 39 //
 40 #ifndef HIGH_PRECISION
 41 #  define HIGH_PRECISION 1
 42 #endif
 43 
 44 #if HIGH_PRECISION
 45 using Float = double;
 46 #else
 47 using Float = float;
 48 #endif
 49 
 50 // Following values have been taken from limits.h
 51 // and temporarly defined for portability on HP-UX.
 52 
 53 #ifndef DBL_MIN /* Min decimal value of a double */
 54 #  define DBL_MIN std::numeric_limits<double>::min()  // 2.2250738585072014e-308
 55 #endif
 56 
 57 #ifndef DBL_DIG /* Digits of precision of a double */
 58 #  define DBL_DIG std::numeric_limits<double>::digits10  // 15
 59 #endif
 60 
 61 #ifndef DBL_MAX /* Max decimal value of a double */
 62 #  define DBL_MAX std::numeric_limits<double>::max()  // 1.7976931348623157e+308
 63 #endif
 64 
 65 #ifndef DBL_EPSILON
 66 #  define DBL_EPSILON std::numeric_limits<double>::epsilon()
 67 #endif  // 2.2204460492503131e-16
 68 
 69 #ifndef FLT_MIN /* Min decimal value of a float */
 70 #  define FLT_MIN std::numeric_limits<float>::min()  // 1.17549435e-38F
 71 #endif
 72 
 73 #ifndef FLT_DIG /* Digits of precision of a float */
 74 #  define FLT_DIG std::numeric_limits<float>::digits10  // 6
 75 #endif
 76 
 77 #ifndef FLT_MAX /* Max decimal value of a float */
 78 #  define FLT_MAX std::numeric_limits<float>::max()  // 3.40282347e+38F
 79 #endif
 80 
 81 #ifndef FLT_EPSILON
 82 #  define FLT_EPSILON std::numeric_limits<float>::epsilon()
 83 #endif  // 1.192092896e-07F
 84 
 85 #ifndef MAXFLOAT /* Max decimal value of a float */
 86 #  define MAXFLOAT std::numeric_limits<float>::max()  // 3.40282347e+38F
 87 #endif
 88 
 89 #ifndef INT_MAX /* Max decimal value of a int */
 90 #  define INT_MAX std::numeric_limits<int>::max()  // 2147483647
 91 #endif
 92 
 93 #ifndef INT_MIN /* Min decimal value of a int */
 94 #  define INT_MIN std::numeric_limits<int>::min()  // -2147483648
 95 #endif
 96 
 97 #ifndef LOG_EKIN_MIN /* Min value of the natural logarithm of kin. energy. */
 98 #  define LOG_EKIN_MIN -30
 99 #endif
100 
101 //---------------------------------
102 
103 template <class T>
104 inline void G4SwapPtr(T*& a, T*& b)
105 {
106   T* tmp = a;
107   a      = b;
108   b      = tmp;
109 }
110 
111 template <class T>
112 inline void G4SwapObj(T* a, T* b)
113 {
114   T tmp = *a;
115   *a    = *b;
116   *b    = tmp;
117 }
118 
119 //-----------------------------
120 
121 #ifndef G4_SQR_DEFINED
122 #  define G4_SQR_DEFINED
123 #  ifdef sqr
124 #    undef sqr
125 #  endif
126 
127 template <class T>
128 inline T sqr(const T& x)
129 {
130   return x * x;
131 }
132 #endif
133 
134 inline int G4lrint(double ad)
135 {
136   return (int)std::lrint(ad);
137 }
138 
139 //-----------------------------
140 
141 //  Use the following function to get rid of "unused parameter" warnings
142 //  Example:
143 //
144 //      #ifdef SOME_CONDITION
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 -- will be "optimized" out
173 //              G4ConsumeParameters(val);
174 //          }
175 //
176 template <typename... _Args>
177 inline void G4ConsumeParameters(_Args&&...)
178 {}
179 
180 #endif  // templates_hh
181