150 lines
4.7 KiB
C++
150 lines
4.7 KiB
C++
//
|
|
// ********************************************************************
|
|
// * DISCLAIMER *
|
|
// * *
|
|
// * The following disclaimer summarizes all the specific disclaimers *
|
|
// * of contributors to this software. The specific disclaimers,which *
|
|
// * govern, are listed with their locations in: *
|
|
// * http://cern.ch/geant4/license *
|
|
// * *
|
|
// * Neither the authors of this software system, nor their employing *
|
|
// * institutes,nor the agencies providing financial support for this *
|
|
// * work make any representation or warranty, express or implied, *
|
|
// * regarding this software system or assume any liability for its *
|
|
// * use. *
|
|
// * *
|
|
// * This code implementation is the intellectual property of the *
|
|
// * GEANT4 collaboration. *
|
|
// * By copying, distributing or modifying the Program (or any work *
|
|
// * based on the Program) you indicate your acceptance of this *
|
|
// * statement, and all its terms. *
|
|
// ********************************************************************
|
|
//
|
|
//
|
|
// $Id: templates.hh,v 1.9 2005/12/02 13:42:49 gcosmo Exp $
|
|
// GEANT4 tag $Name: geant4-08-00 $
|
|
//
|
|
//
|
|
// -*- C++ -*-
|
|
//
|
|
// -----------------------------------------------------------------------
|
|
// This file should define some platform dependent features and some
|
|
// useful utilities.
|
|
// -----------------------------------------------------------------------
|
|
|
|
// =======================================================================
|
|
// Gabriele Cosmo - Created: 5th September 1995
|
|
// Gabriele Cosmo - Minor change: 08/02/1996
|
|
// Gabriele Cosmo - Added DBL_MIN, FLT_MIN, DBL_DIG,
|
|
// DBL_MAX, FLT_DIG, FLT_MAX : 12/04/1996
|
|
// Gabriele Cosmo - Removed boolean enum definition : 29/11/1996
|
|
// Gunter Folger - Added G4SwapPtr() and G4SwapObj() : 31/07/1997
|
|
// Gabriele Cosmo - Adapted signatures of min(), max() to
|
|
// STL's ones, thanks to E.Tcherniaev : 31/07/1997
|
|
// Gabriele Cosmo,
|
|
// Evgueni Tcherniaev - Migrated to CLHEP: 04/12/1997
|
|
// =======================================================================
|
|
|
|
#ifndef templates_h
|
|
#define templates_h 1
|
|
|
|
#include <limits>
|
|
|
|
//
|
|
// If HIGH_PRECISION is defined to TRUE (ie. != 0) then the type "Float"
|
|
// is typedefed to "double". If it is FALSE (ie. 0) it is typedefed
|
|
// to "float".
|
|
//
|
|
#ifndef HIGH_PRECISION
|
|
#define HIGH_PRECISION 1
|
|
#endif
|
|
|
|
#if HIGH_PRECISION
|
|
typedef double Float;
|
|
#else
|
|
typedef float Float;
|
|
#endif
|
|
|
|
// Following values have been taken from limits.h
|
|
// and temporarly defined for portability on HP-UX.
|
|
|
|
#ifndef DBL_MIN /* Min decimal value of a double */
|
|
#define DBL_MIN std::numeric_limits<double>::min() // 2.2250738585072014e-308
|
|
#endif
|
|
|
|
#ifndef DBL_DIG /* Digits of precision of a double */
|
|
#define DBL_DIG std::numeric_limits<double>::digits10 // 15
|
|
#endif
|
|
|
|
#ifndef DBL_MAX /* Max decimal value of a double */
|
|
#define DBL_MAX std::numeric_limits<double>::max() // 1.7976931348623157e+308
|
|
#endif
|
|
|
|
#ifndef DBL_EPSILON
|
|
#define DBL_EPSILON std::numeric_limits<double>::epsilon()
|
|
#endif // 2.2204460492503131e-16
|
|
|
|
#ifndef FLT_MIN /* Min decimal value of a float */
|
|
#define FLT_MIN std::numeric_limits<float>::min() // 1.17549435e-38F
|
|
#endif
|
|
|
|
#ifndef FLT_DIG /* Digits of precision of a float */
|
|
#define FLT_DIG std::numeric_limits<float>::digits10 // 6
|
|
#endif
|
|
|
|
#ifndef FLT_MAX /* Max decimal value of a float */
|
|
#define FLT_MAX std::numeric_limits<float>::max() // 3.40282347e+38F
|
|
#endif
|
|
|
|
#ifndef FLT_EPSILON
|
|
#define FLT_EPSILON std::numeric_limits<float>::epsilon()
|
|
#endif // 1.192092896e-07F
|
|
|
|
#ifndef MAXFLOAT /* Max decimal value of a float */
|
|
#define MAXFLOAT std::numeric_limits<float>::max() // 3.40282347e+38F
|
|
#endif
|
|
|
|
//---------------------------------
|
|
|
|
template <class T>
|
|
inline void G4SwapPtr(T* a, T* b) {
|
|
T* tmp=a;
|
|
a = b;
|
|
b = tmp;
|
|
}
|
|
|
|
template <class T>
|
|
inline void G4SwapObj(T* a, T* b) {
|
|
T tmp= *a;
|
|
*a = *b;
|
|
*b = tmp;
|
|
}
|
|
|
|
//-----------------------------
|
|
|
|
#ifndef G4_SQR_DEFINED
|
|
#define G4_SQR_DEFINED
|
|
#ifdef sqr
|
|
#undef sqr
|
|
#endif
|
|
|
|
template <class T>
|
|
inline T sqr(const T& x)
|
|
{
|
|
return x*x;
|
|
}
|
|
#endif
|
|
|
|
#ifdef G4_ABS_DEFINED
|
|
#ifdef abs
|
|
#undef abs
|
|
#endif
|
|
template <class T>
|
|
inline T std::abs(const T& a)
|
|
{
|
|
return a < 0 ? -a : a;
|
|
}
|
|
#endif
|
|
|
|
#endif // templates_h
|