npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
PreciseType.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_PRECISETYPE_HH_
2 #define NPSTAT_PRECISETYPE_HH_
3 
4 /*!
5 // \file PreciseType.hh
6 //
7 // \brief Compile-time deduction of an appropriate precise numeric type
8 //
9 // Author: I. Volobouev
10 //
11 // January 2012
12 */
13 
14 #include <complex>
15 
16 #include "geners/IOIsNumber.hh"
17 #include "npstat/nm/lapack_double.h"
18 
19 namespace npstat {
20  template <class T, int I=0>
22  {
23  typedef T type;
24  };
25 
26 #ifdef USE_LAPACK_QUAD
27  template <class T>
28  struct PreciseTypeHelper<T, 1>
29  {
30  typedef lapack_double type;
31  };
32 #else
33  template <class T>
34  struct PreciseTypeHelper<T, 1>
35  {
36  typedef long double type;
37  };
38 #endif
39 
40  /**
41  // Use "long double" as the most precise type among various built-in
42  // numeric types, std::complex<long double> for complex types, and
43  // the type itself for other types.
44  */
45  template <class T>
46  struct PreciseType
47  {
48  typedef typename PreciseTypeHelper<T,gs::IOIsNumber<T>::value>::type type;
49  };
50 
51 #ifdef USE_LAPACK_QUAD
52  template <class T>
53  struct PreciseType<std::complex<T> >
54  {
55  typedef std::complex<lapack_double> type;
56  };
57 
58  template <class T>
59  struct PreciseType<const std::complex<T> >
60  {
61  typedef std::complex<lapack_double> type;
62  };
63 
64  template <class T>
65  struct PreciseType<volatile std::complex<T> >
66  {
67  typedef std::complex<lapack_double> type;
68  };
69 
70  template <class T>
71  struct PreciseType<const volatile std::complex<T> >
72  {
73  typedef std::complex<lapack_double> type;
74  };
75 #else
76  template <class T>
77  struct PreciseType<std::complex<T> >
78  {
79  typedef std::complex<long double> type;
80  };
81 
82  template <class T>
83  struct PreciseType<const std::complex<T> >
84  {
85  typedef std::complex<long double> type;
86  };
87 
88  template <class T>
89  struct PreciseType<volatile std::complex<T> >
90  {
91  typedef std::complex<long double> type;
92  };
93 
94  template <class T>
95  struct PreciseType<const volatile std::complex<T> >
96  {
97  typedef std::complex<long double> type;
98  };
99 #endif
100 }
101 
102 #endif // NPSTAT_PRECISETYPE_HH_
Definition: AbsArrayProjector.hh:14
Definition: PreciseType.hh:22
Definition: PreciseType.hh:47