Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:33

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 // Module defining platform dependent features and some useful utilities.
0027 
0028 // Author: Gabriele Cosmo, 5 September 1995 - Created
0029 // --------------------------------------------------------------------
0030 #ifndef templates_hh
0031 #define templates_hh 1
0032 
0033 #include <climits>
0034 #include <limits>
0035 
0036 // If HIGH_PRECISION is defined to TRUE (ie. != 0) then the type "Float"
0037 // is typedefed to "double". If it is FALSE (ie. 0) it is typedefed
0038 // to "float".
0039 //
0040 #ifndef HIGH_PRECISION
0041 #  define HIGH_PRECISION 1
0042 #endif
0043 
0044 #if HIGH_PRECISION
0045 using Float = double;
0046 #else
0047 using Float = float;
0048 #endif
0049 
0050 // Following values have been taken from limits.h
0051 // and temporarly defined for portability on HP-UX.
0052 
0053 #ifndef DBL_MIN /* Min decimal value of a double */
0054 #  define DBL_MIN std::numeric_limits<double>::min()  // 2.2250738585072014e-308
0055 #endif
0056 
0057 #ifndef DBL_DIG /* Digits of precision of a double */
0058 #  define DBL_DIG std::numeric_limits<double>::digits10  // 15
0059 #endif
0060 
0061 #ifndef DBL_MAX /* Max decimal value of a double */
0062 #  define DBL_MAX std::numeric_limits<double>::max()  // 1.7976931348623157e+308
0063 #endif
0064 
0065 #ifndef DBL_EPSILON
0066 #  define DBL_EPSILON std::numeric_limits<double>::epsilon()
0067 #endif  // 2.2204460492503131e-16
0068 
0069 #ifndef FLT_MIN /* Min decimal value of a float */
0070 #  define FLT_MIN std::numeric_limits<float>::min()  // 1.17549435e-38F
0071 #endif
0072 
0073 #ifndef FLT_DIG /* Digits of precision of a float */
0074 #  define FLT_DIG std::numeric_limits<float>::digits10  // 6
0075 #endif
0076 
0077 #ifndef FLT_MAX /* Max decimal value of a float */
0078 #  define FLT_MAX std::numeric_limits<float>::max()  // 3.40282347e+38F
0079 #endif
0080 
0081 #ifndef FLT_EPSILON
0082 #  define FLT_EPSILON std::numeric_limits<float>::epsilon()
0083 #endif  // 1.192092896e-07F
0084 
0085 #ifndef MAXFLOAT /* Max decimal value of a float */
0086 #  define MAXFLOAT std::numeric_limits<float>::max()  // 3.40282347e+38F
0087 #endif
0088 
0089 #ifndef INT_MAX /* Max decimal value of a int */
0090 #  define INT_MAX std::numeric_limits<int>::max()  // 2147483647
0091 #endif
0092 
0093 #ifndef INT_MIN /* Min decimal value of a int */
0094 #  define INT_MIN std::numeric_limits<int>::min()  // -2147483648
0095 #endif
0096 
0097 #ifndef LOG_EKIN_MIN /* Min value of the natural logarithm of kin. energy. */
0098 #  define LOG_EKIN_MIN -30
0099 #endif
0100 
0101 //---------------------------------
0102 
0103 template <class T>
0104 inline void G4SwapPtr(T*& a, T*& b)
0105 {
0106   T* tmp = a;
0107   a      = b;
0108   b      = tmp;
0109 }
0110 
0111 template <class T>
0112 inline void G4SwapObj(T* a, T* b)
0113 {
0114   T tmp = *a;
0115   *a    = *b;
0116   *b    = tmp;
0117 }
0118 
0119 //-----------------------------
0120 
0121 #ifndef G4_SQR_DEFINED
0122 #  define G4_SQR_DEFINED
0123 #  ifdef sqr
0124 #    undef sqr
0125 #  endif
0126 
0127 template <class T>
0128 inline T sqr(const T& x)
0129 {
0130   return x * x;
0131 }
0132 #endif
0133 
0134 inline int G4lrint(double ad)
0135 {
0136   return (int)std::lrint(ad);
0137 }
0138 
0139 //-----------------------------
0140 
0141 //  Use the following function to get rid of "unused parameter" warnings
0142 //  Example:
0143 //
0144 //      #ifdef SOME_CONDITION
0145 //          void doSomething(int val)
0146 //          {
0147 //              something = val;
0148 //          }
0149 //      #else
0150 //          void doSomething(int)
0151 //          { }
0152 //      #endif
0153 //
0154 //  can be simplified to:
0155 //
0156 //          void doSomething(int val)
0157 //          {
0158 //      #ifdef SOME_CONDITION
0159 //              something = val;
0160 //      #else
0161 //              G4ConsumeParameters(val);
0162 //      #endif
0163 //          }
0164 //
0165 //  or:
0166 //
0167 //          void doSomething(int val)
0168 //          {
0169 //      #ifdef SOME_CONDITION
0170 //              something = val;
0171 //      #endif
0172 //              // function call does nothing -- will be "optimized" out
0173 //              G4ConsumeParameters(val);
0174 //          }
0175 //
0176 template <typename... _Args>
0177 inline void G4ConsumeParameters(_Args&&...)
0178 {}
0179 
0180 #endif  // templates_hh