| 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 | //
|
|---|
| 27 | // $Id: templates.hh,v 1.13 2008/08/15 12:15:53 gcosmo Exp $
|
|---|
| 28 | // GEANT4 tag $Name: geant4-09-03 $
|
|---|
| 29 | //
|
|---|
| 30 | //
|
|---|
| 31 | // -*- C++ -*-
|
|---|
| 32 | //
|
|---|
| 33 | // -----------------------------------------------------------------------
|
|---|
| 34 | // This file should define some platform dependent features and some
|
|---|
| 35 | // useful utilities.
|
|---|
| 36 | // -----------------------------------------------------------------------
|
|---|
| 37 |
|
|---|
| 38 | // =======================================================================
|
|---|
| 39 | // Gabriele Cosmo - Created: 5th September 1995
|
|---|
| 40 | // Gabriele Cosmo - Minor change: 08/02/1996
|
|---|
| 41 | // Gabriele Cosmo - Added DBL_MIN, FLT_MIN, DBL_DIG,
|
|---|
| 42 | // DBL_MAX, FLT_DIG, FLT_MAX : 12/04/1996
|
|---|
| 43 | // Gabriele Cosmo - Removed boolean enum definition : 29/11/1996
|
|---|
| 44 | // Gunter Folger - Added G4SwapPtr() and G4SwapObj() : 31/07/1997
|
|---|
| 45 | // Gabriele Cosmo - Adapted signatures of min(), max() to
|
|---|
| 46 | // STL's ones, thanks to E.Tcherniaev : 31/07/1997
|
|---|
| 47 | // Gabriele Cosmo,
|
|---|
| 48 | // Evgueni Tcherniaev - Migrated to CLHEP: 04/12/1997
|
|---|
| 49 | // =======================================================================
|
|---|
| 50 |
|
|---|
| 51 | #ifndef templates_h
|
|---|
| 52 | #define templates_h 1
|
|---|
| 53 |
|
|---|
| 54 | #include <limits>
|
|---|
| 55 | #include <climits>
|
|---|
| 56 |
|
|---|
| 57 | //
|
|---|
| 58 | // If HIGH_PRECISION is defined to TRUE (ie. != 0) then the type "Float"
|
|---|
| 59 | // is typedefed to "double". If it is FALSE (ie. 0) it is typedefed
|
|---|
| 60 | // to "float".
|
|---|
| 61 | //
|
|---|
| 62 | #ifndef HIGH_PRECISION
|
|---|
| 63 | #define HIGH_PRECISION 1
|
|---|
| 64 | #endif
|
|---|
| 65 |
|
|---|
| 66 | #if HIGH_PRECISION
|
|---|
| 67 | typedef double Float;
|
|---|
| 68 | #else
|
|---|
| 69 | typedef float Float;
|
|---|
| 70 | #endif
|
|---|
| 71 |
|
|---|
| 72 | // Following values have been taken from limits.h
|
|---|
| 73 | // and temporarly defined for portability on HP-UX.
|
|---|
| 74 |
|
|---|
| 75 | #ifndef DBL_MIN /* Min decimal value of a double */
|
|---|
| 76 | #define DBL_MIN std::numeric_limits<double>::min() // 2.2250738585072014e-308
|
|---|
| 77 | #endif
|
|---|
| 78 |
|
|---|
| 79 | #ifndef DBL_DIG /* Digits of precision of a double */
|
|---|
| 80 | #define DBL_DIG std::numeric_limits<double>::digits10 // 15
|
|---|
| 81 | #endif
|
|---|
| 82 |
|
|---|
| 83 | #ifndef DBL_MAX /* Max decimal value of a double */
|
|---|
| 84 | #define DBL_MAX std::numeric_limits<double>::max() // 1.7976931348623157e+308
|
|---|
| 85 | #endif
|
|---|
| 86 |
|
|---|
| 87 | #ifndef DBL_EPSILON
|
|---|
| 88 | #define DBL_EPSILON std::numeric_limits<double>::epsilon()
|
|---|
| 89 | #endif // 2.2204460492503131e-16
|
|---|
| 90 |
|
|---|
| 91 | #ifndef FLT_MIN /* Min decimal value of a float */
|
|---|
| 92 | #define FLT_MIN std::numeric_limits<float>::min() // 1.17549435e-38F
|
|---|
| 93 | #endif
|
|---|
| 94 |
|
|---|
| 95 | #ifndef FLT_DIG /* Digits of precision of a float */
|
|---|
| 96 | #define FLT_DIG std::numeric_limits<float>::digits10 // 6
|
|---|
| 97 | #endif
|
|---|
| 98 |
|
|---|
| 99 | #ifndef FLT_MAX /* Max decimal value of a float */
|
|---|
| 100 | #define FLT_MAX std::numeric_limits<float>::max() // 3.40282347e+38F
|
|---|
| 101 | #endif
|
|---|
| 102 |
|
|---|
| 103 | #ifndef FLT_EPSILON
|
|---|
| 104 | #define FLT_EPSILON std::numeric_limits<float>::epsilon()
|
|---|
| 105 | #endif // 1.192092896e-07F
|
|---|
| 106 |
|
|---|
| 107 | #ifndef MAXFLOAT /* Max decimal value of a float */
|
|---|
| 108 | #define MAXFLOAT std::numeric_limits<float>::max() // 3.40282347e+38F
|
|---|
| 109 | #endif
|
|---|
| 110 |
|
|---|
| 111 | //---------------------------------
|
|---|
| 112 |
|
|---|
| 113 | template <class T>
|
|---|
| 114 | inline void G4SwapPtr(T*& a, T*& b) {
|
|---|
| 115 | T* tmp= a;
|
|---|
| 116 | a = b;
|
|---|
| 117 | b = tmp;
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | template <class T>
|
|---|
| 121 | inline void G4SwapObj(T* a, T* b) {
|
|---|
| 122 | T tmp= *a;
|
|---|
| 123 | *a = *b;
|
|---|
| 124 | *b = tmp;
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | //-----------------------------
|
|---|
| 128 |
|
|---|
| 129 | #ifndef G4_SQR_DEFINED
|
|---|
| 130 | #define G4_SQR_DEFINED
|
|---|
| 131 | #ifdef sqr
|
|---|
| 132 | #undef sqr
|
|---|
| 133 | #endif
|
|---|
| 134 |
|
|---|
| 135 | template <class T>
|
|---|
| 136 | inline T sqr(const T& x)
|
|---|
| 137 | {
|
|---|
| 138 | return x*x;
|
|---|
| 139 | }
|
|---|
| 140 | #endif
|
|---|
| 141 |
|
|---|
| 142 | #ifdef G4_ABS_DEFINED
|
|---|
| 143 | #ifdef abs
|
|---|
| 144 | #undef abs
|
|---|
| 145 | #endif
|
|---|
| 146 | template <class T>
|
|---|
| 147 | inline T std::abs(const T& a)
|
|---|
| 148 | {
|
|---|
| 149 | return a < 0 ? -a : a;
|
|---|
| 150 | }
|
|---|
| 151 | #endif
|
|---|
| 152 |
|
|---|
| 153 | #endif // templates_h
|
|---|