Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
templates.hh
Go to the documentation of this file.
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 67970 2013-03-13 10:10:06Z 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 // =======================================================================
49 
50 #ifndef templates_h
51 #define templates_h 1
52 
53 #include <limits>
54 #include <climits>
55 
56 //
57 // If HIGH_PRECISION is defined to TRUE (ie. != 0) then the type "Float"
58 // is typedefed to "double". If it is FALSE (ie. 0) it is typedefed
59 // to "float".
60 //
61 #ifndef HIGH_PRECISION
62 #define HIGH_PRECISION 1
63 #endif
64 
65 #if HIGH_PRECISION
66 typedef double Float;
67 #else
68 typedef float Float;
69 #endif
70 
71 // Following values have been taken from limits.h
72 // and temporarly defined for portability on HP-UX.
73 
74 #ifndef DBL_MIN /* Min decimal value of a double */
75 #define DBL_MIN std::numeric_limits<double>::min() // 2.2250738585072014e-308
76 #endif
77 
78 #ifndef DBL_DIG /* Digits of precision of a double */
79 #define DBL_DIG std::numeric_limits<double>::digits10 // 15
80 #endif
81 
82 #ifndef DBL_MAX /* Max decimal value of a double */
83 #define DBL_MAX std::numeric_limits<double>::max() // 1.7976931348623157e+308
84 #endif
85 
86 #ifndef DBL_EPSILON
87 #define DBL_EPSILON std::numeric_limits<double>::epsilon()
88 #endif // 2.2204460492503131e-16
89 
90 #ifndef FLT_MIN /* Min decimal value of a float */
91 #define FLT_MIN std::numeric_limits<float>::min() // 1.17549435e-38F
92 #endif
93 
94 #ifndef FLT_DIG /* Digits of precision of a float */
95 #define FLT_DIG std::numeric_limits<float>::digits10 // 6
96 #endif
97 
98 #ifndef FLT_MAX /* Max decimal value of a float */
99 #define FLT_MAX std::numeric_limits<float>::max() // 3.40282347e+38F
100 #endif
101 
102 #ifndef FLT_EPSILON
103 #define FLT_EPSILON std::numeric_limits<float>::epsilon()
104 #endif // 1.192092896e-07F
105 
106 #ifndef MAXFLOAT /* Max decimal value of a float */
107 #define MAXFLOAT std::numeric_limits<float>::max() // 3.40282347e+38F
108 #endif
109 
110 #ifndef INT_MAX /* Max decimal value of a int */
111 #define INT_MAX std::numeric_limits<int>::max() // 2147483647
112 #endif
113 
114 #ifndef INT_MIN /* Min decimal value of a int */
115 #define INT_MIN std::numeric_limits<int>::min() // -2147483648
116 #endif
117 
118 //---------------------------------
119 
120 template <class T>
121 inline void G4SwapPtr(T*& a, T*& b)
122 {
123  T* tmp= a;
124  a = b;
125  b = tmp;
126 }
127 
128 template <class T>
129 inline void G4SwapObj(T* a, T* b)
130 {
131  T tmp= *a;
132  *a = *b;
133  *b = tmp;
134 }
135 
136 //-----------------------------
137 
138 #ifndef G4_SQR_DEFINED
139  #define G4_SQR_DEFINED
140  #ifdef sqr
141  #undef sqr
142  #endif
143 
144 template <class T>
145 inline T sqr(const T& x)
146 {
147  return x*x;
148 }
149 #endif
150 
151 #ifdef G4_ABS_DEFINED
152  #ifdef abs
153  #undef abs
154  #endif
155 
156 template <class T>
157 inline T std::abs(const T& a)
158 {
159  return a < 0 ? -a : a;
160 }
161 #endif
162 
163 inline int G4lrint(double ad)
164 {
165  return (ad>0) ? static_cast<int>(ad+.5) : static_cast<int>(ad-.5);
166 }
167 
168 inline int G4lint(double ad)
169 {
170  return (ad>0) ? static_cast<int>(ad) : static_cast<int>(ad-1.);
171 }
172 
173 inline int G4rint(double ad)
174 {
175  return (ad>0) ? static_cast<int>(ad+1) : static_cast<int>(ad);
176 }
177 
178 #endif // templates_h
void G4SwapObj(T *a, T *b)
Definition: templates.hh:129
int G4rint(double ad)
Definition: templates.hh:173
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
tuple x
Definition: test.py:50
tuple b
Definition: test.py:12
int G4lrint(double ad)
Definition: templates.hh:163
void G4SwapPtr(T *&a, T *&b)
Definition: templates.hh:121
double Float
Definition: templates.hh:66
int G4lint(double ad)
Definition: templates.hh:168
T sqr(const T &x)
Definition: templates.hh:145