CMS 3D CMS Logo

absDifference.h
Go to the documentation of this file.
1 #ifndef NPSTAT_ABSDIFFERENCE_HH_
2 #define NPSTAT_ABSDIFFERENCE_HH_
3 
15 #include <cmath>
16 #include <complex>
17 
18 #include "Alignment/Geners/interface/IOIsUnsigned.hh"
19 
20 namespace npstat {
21  namespace Private {
22  template <typename T>
23  struct AbsReturnType {
24  typedef T type;
25  };
26 
27  template <typename T>
28  struct AbsReturnType<std::complex<T> > {
29  typedef T type;
30  };
31 
32  template <typename T>
33  struct AbsReturnType<const std::complex<T> > {
34  typedef T type;
35  };
36 
37  template <typename T>
38  struct AbsReturnType<volatile std::complex<T> > {
39  typedef T type;
40  };
41 
42  template <typename T>
43  struct AbsReturnType<const volatile std::complex<T> > {
44  typedef T type;
45  };
46 
47  // Signed type
48  template <typename T, int Unsigned = 0>
49  struct AbsHelper {
51 
52  inline static return_type delta(const T& v1, const T& v2) { return std::abs(v1 - v2); }
53 
54  inline static return_type value(const T& v1) { return std::abs(v1); }
55  };
56 
57  // Unsigned type
58  template <typename T>
59  struct AbsHelper<T, 1> {
61 
62  inline static return_type delta(const T& v1, const T& v2) { return v1 > v2 ? v1 - v2 : v2 - v1; }
63 
64  inline static return_type value(const T& v1) { return v1; }
65  };
66  } // namespace Private
67 
72  template <typename T>
73  inline typename Private::AbsReturnType<T>::type absDifference(const T& v1, const T& v2) {
75  }
76 
81  template <typename T>
82  inline typename Private::AbsReturnType<T>::type absValue(const T& v1) {
84  }
85 } // namespace npstat
86 
87 #endif // NPSTAT_ABSDIFFERENCE_HH_
static return_type delta(const T &v1, const T &v2)
Definition: absDifference.h:62
static return_type value(const T &v1)
Definition: absDifference.h:64
Private::AbsReturnType< T >::type absDifference(const T &v1, const T &v2)
Definition: absDifference.h:73
static return_type value(const T &v1)
Definition: absDifference.h:54
Private::AbsReturnType< T >::type return_type
Definition: absDifference.h:50
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Private::AbsReturnType< T >::type absValue(const T &v1)
Definition: absDifference.h:82
Private::AbsReturnType< T >::type return_type
Definition: absDifference.h:60
static return_type delta(const T &v1, const T &v2)
Definition: absDifference.h:52
long double T