Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:21:33

0001 #ifndef NPSTAT_PRECISETYPE_HH_
0002 #define NPSTAT_PRECISETYPE_HH_
0003 
0004 /*!
0005 // \file PreciseType.h
0006 //
0007 // \brief Compile-time deduction of an appropriate precise numeric type
0008 //
0009 // Author: I. Volobouev
0010 //
0011 // January 2012
0012 */
0013 
0014 #include <complex>
0015 
0016 #include "Alignment/Geners/interface/IOIsNumber.hh"
0017 
0018 namespace npstat {
0019   template <class T, int I = 0>
0020   struct PreciseTypeHelper {
0021     typedef T type;
0022   };
0023 
0024   template <class T>
0025   struct PreciseTypeHelper<T, 1> {
0026     typedef long double type;
0027   };
0028 
0029   /**
0030     // Use "long double" as the most precise type among various simple
0031     // numeric types, std::complex<long double> for complex types, and
0032     // the type itself for other types.
0033     */
0034   template <class T>
0035   struct PreciseType {
0036     typedef typename PreciseTypeHelper<T, gs::IOIsNumber<T>::value>::type type;
0037   };
0038 
0039   template <class T>
0040   struct PreciseType<std::complex<T> > {
0041     typedef std::complex<long double> type;
0042   };
0043 
0044   template <class T>
0045   struct PreciseType<const std::complex<T> > {
0046     typedef std::complex<long double> type;
0047   };
0048 
0049   template <class T>
0050   struct PreciseType<volatile std::complex<T> > {
0051     typedef std::complex<long double> type;
0052   };
0053 
0054   template <class T>
0055   struct PreciseType<const volatile std::complex<T> > {
0056     typedef std::complex<long double> type;
0057   };
0058 }  // namespace npstat
0059 
0060 #endif  // NPSTAT_PRECISETYPE_HH_