Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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// 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
45using Float = double;
46#else
47using 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
103template <class T>
104inline void G4SwapPtr(T*& a, T*& b)
105{
106 T* tmp = a;
107 a = b;
108 b = tmp;
109}
110
111template <class T>
112inline 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
127template <class T>
128inline T sqr(const T& x)
129{
130 return x * x;
131}
132#endif
133
134inline 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//
176template <typename... _Args>
177inline void G4ConsumeParameters(_Args&&...)
178{}
179
180#endif // templates_hh
void G4SwapObj(T *a, T *b)
Definition: templates.hh:112
int G4lrint(double ad)
Definition: templates.hh:134
T sqr(const T &x)
Definition: templates.hh:128
double Float
Definition: templates.hh:45
void G4SwapPtr(T *&a, T *&b)
Definition: templates.hh:104
void G4ConsumeParameters(_Args &&...)
Definition: templates.hh:177