npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
ComplexComparesAbs.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_COMPLEXCOMPARESABS_HH_
2 #define NPSTAT_COMPLEXCOMPARESABS_HH_
3 
4 /*!
5 // \file ComplexComparesAbs.hh
6 //
7 // \brief Ordering extended to complex numbers by comparing their magnitudes
8 //
9 // Author: I. Volobouev
10 //
11 // January 2012
12 */
13 
14 #include <cmath>
15 #include <complex>
16 
17 namespace npstat {
18  /**
19  // This template compares two numbers. For simple numeric types
20  // (int, double, etc) the numbers themselves are compared while
21  // for std::complex<...> types absolute values are compared.
22  */
23  template <class T>
25  {
26  inline static bool less(const T& l, const T& r)
27  {return l < r;}
28 
29  inline static bool more(const T& l, const T& r)
30  {return l > r;}
31  };
32 
33  template <class T>
34  struct ComplexComparesAbs<std::complex<T> >
35  {
36  inline static bool less(const std::complex<T>& l,
37  const std::complex<T>& r)
38  {return std::abs(l) < std::abs(r);}
39 
40  inline static bool more(const std::complex<T>& l,
41  const std::complex<T>& r)
42  {return std::abs(l) > std::abs(r);}
43  };
44 }
45 
46 #endif // NPSTAT_COMPLEXCOMPARESABS_HH_
Definition: AbsArrayProjector.hh:14
Definition: ComplexComparesAbs.hh:25