Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:19:19

0001 #ifndef NPSTAT_COMPLEXCOMPARESABS_HH_
0002 #define NPSTAT_COMPLEXCOMPARESABS_HH_
0003 
0004 /*!
0005 // \file ComplexComparesAbs.h
0006 //
0007 // \brief Ordering extended to complex numbers by comparing their magnitudes
0008 //
0009 // Author: I. Volobouev
0010 //
0011 // January 2012
0012 */
0013 
0014 #include <cmath>
0015 #include <complex>
0016 
0017 namespace npstat {
0018   /**
0019     // This template compares two numbers. For simple numeric types
0020     // (int, double, etc) the numbers themselves are compared while
0021     // for std::complex<...> types absolute values are compared.
0022     */
0023   template <class T>
0024   struct ComplexComparesAbs {
0025     inline static bool less(const T& l, const T& r) { return l < r; }
0026 
0027     inline static bool more(const T& l, const T& r) { return l > r; }
0028   };
0029 
0030   template <class T>
0031   struct ComplexComparesAbs<std::complex<T> > {
0032     inline static bool less(const std::complex<T>& l, const std::complex<T>& r) { return std::abs(l) < std::abs(r); }
0033 
0034     inline static bool more(const std::complex<T>& l, const std::complex<T>& r) { return std::abs(l) > std::abs(l); }
0035   };
0036 }  // namespace npstat
0037 
0038 #endif  // NPSTAT_COMPLEXCOMPARESABS_HH_