Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/eqT is written in an unsupported language. File is not indexed.

0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003 
0004 #ifndef tools_eqT
0005 #define tools_eqT
0006 
0007 namespace tools {
0008 
0009 template <class NUMBER,class PREC>
0010 inline bool numbers_are_equal(const NUMBER& a_left,const NUMBER& a_right,const PREC& a_prec,PREC(*a_fabs)(const NUMBER&)) {
0011   NUMBER diff = a_left - a_right;
0012   if(a_fabs(diff)>=a_prec) return false;
0013   return true;
0014 }
0015 
0016 template <class NUMBER,class PREC>
0017 inline bool is_zero(const NUMBER& a_left,const PREC& a_prec,PREC(*a_fabs)(const NUMBER&)) {
0018   if(a_fabs(a_left)>=a_prec) return false;
0019   return true;
0020 }
0021 
0022 template <class VEC,class PREC>
0023 inline bool vectors_are_equal(const VEC& a_1,const VEC& a_2,const PREC& a_prec,PREC(*a_fabs)(const PREC&)) {
0024   if(a_1.size()!=a_2.size()) return false;
0025   typedef typename VEC::size_type sz_t;
0026   sz_t sz = a_1.size();
0027   for(sz_t index=0;index<sz;index++) {
0028     if(!numbers_are_equal(a_1[index],a_2[index],a_prec,a_fabs))
0029       return false;
0030   }
0031   return true;
0032 }
0033 
0034 template <class VECVEC,class PREC>
0035 inline bool vecvecs_are_equal(const VECVEC& a_1,const VECVEC& a_2,const PREC& a_prec,PREC(*a_fabs)(const PREC&)) {
0036   if(a_1.size()!=a_2.size()) return false;
0037   typedef typename VECVEC::size_type sz_t;
0038   sz_t sz = a_1.size();
0039   for(sz_t index=0;index<sz;index++) {
0040     if(!vectors_are_equal(a_1[index],a_2[index],a_prec,a_fabs)) return false;
0041   }
0042   return true;
0043 }
0044 
0045 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
0046 /// PREC(*a_fabs)(PREC) : /////////////////////////////////////////////////////////////////////////////////////
0047 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
0048 
0049 // for histo equals functions.
0050 
0051 template <class NUMBER,class PREC>
0052 inline bool numbers_are_equal(const NUMBER& a_left,const NUMBER& a_right,const PREC& a_prec,PREC(*a_fabs)(NUMBER)) {
0053   NUMBER diff = a_left - a_right;
0054   if(a_fabs(diff)>=a_prec) return false;
0055   return true;
0056 }
0057 
0058 template <class VEC,class PREC>
0059 inline bool vectors_are_equal(const VEC& a_1,const VEC& a_2,const PREC& a_prec,PREC(*a_fabs)(PREC)) {
0060   if(a_1.size()!=a_2.size()) return false;
0061   typedef typename VEC::size_type sz_t;
0062   sz_t sz = a_1.size();
0063   for(sz_t index=0;index<sz;index++) {
0064     if(!numbers_are_equal(a_1[index],a_2[index],a_prec,a_fabs))
0065       return false;
0066   }
0067   return true;
0068 }
0069 
0070 template <class VECVEC,class PREC>
0071 inline bool vecvecs_are_equal(const VECVEC& a_1,const VECVEC& a_2,const PREC& a_prec,PREC(*a_fabs)(PREC)) {
0072   if(a_1.size()!=a_2.size()) return false;
0073   typedef typename VECVEC::size_type sz_t;
0074   sz_t sz = a_1.size();
0075   for(sz_t index=0;index<sz;index++) {
0076     if(!vectors_are_equal(a_1[index],a_2[index],a_prec,a_fabs)) return false;
0077   }
0078   return true;
0079 }
0080 
0081 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
0082 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
0083 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
0084 
0085 }
0086 
0087 #endif