source: trunk/source/global/management/include/templates.hh@ 1353

Last change on this file since 1353 was 1340, checked in by garnier, 15 years ago

update ti head

File size: 5.2 KB
Line 
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.14 2010/07/16 15:48:51 gcosmo Exp $
28// GEANT4 tag $Name: global-V09-03-22 $
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
67typedef double Float;
68#else
69typedef 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#ifndef INT_MAX /* Max decimal value of a int */
112#define INT_MAX std::numeric_limits<int>::max() // 2147483647
113#endif
114
115#ifndef INT_MIN /* Min decimal value of a int */
116#define INT_MIN std::numeric_limits<int>::min() // -2147483648
117#endif
118
119//---------------------------------
120
121template <class T>
122inline void G4SwapPtr(T*& a, T*& b) {
123 T* tmp= a;
124 a = b;
125 b = tmp;
126}
127
128template <class T>
129inline void G4SwapObj(T* a, T* b) {
130 T tmp= *a;
131 *a = *b;
132 *b = tmp;
133}
134
135//-----------------------------
136
137#ifndef G4_SQR_DEFINED
138 #define G4_SQR_DEFINED
139 #ifdef sqr
140 #undef sqr
141 #endif
142
143template <class T>
144inline T sqr(const T& x)
145{
146 return x*x;
147}
148#endif
149
150#ifdef G4_ABS_DEFINED
151 #ifdef abs
152 #undef abs
153 #endif
154template <class T>
155inline T std::abs(const T& a)
156{
157 return a < 0 ? -a : a;
158}
159#endif
160
161#endif // templates_h
Note: See TracBrowser for help on using the repository browser.