Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 2 // See the file tools.license for terms. 3 4 #ifndef tools_eqT 5 #define tools_eqT 6 7 namespace tools { 8 9 template <class NUMBER,class PREC> 10 inline bool numbers_are_equal(const NUMBER& a_ 11 NUMBER diff = a_left - a_right; 12 if(a_fabs(diff)>=a_prec) return false; 13 return true; 14 } 15 16 template <class NUMBER,class PREC> 17 inline bool is_zero(const NUMBER& a_left,const 18 if(a_fabs(a_left)>=a_prec) return false; 19 return true; 20 } 21 22 template <class VEC,class PREC> 23 inline bool vectors_are_equal(const VEC& a_1,c 24 if(a_1.size()!=a_2.size()) return false; 25 typedef typename VEC::size_type sz_t; 26 sz_t sz = a_1.size(); 27 //bool status = true; 28 for(sz_t index=0;index<sz;index++) { 29 if(!numbers_are_equal(a_1[index],a_2[index 30 //{ ::printf("debug : vectors_are_equals : 31 return false; 32 //status = false; 33 //} 34 } 35 return true; 36 //return status; 37 } 38 39 template <class VECVEC,class PREC> 40 inline bool vecvecs_are_equal(const VECVEC& a_ 41 if(a_1.size()!=a_2.size()) return false; 42 typedef typename VECVEC::size_type sz_t; 43 sz_t sz = a_1.size(); 44 for(sz_t index=0;index<sz;index++) { 45 if(!vectors_are_equal(a_1[index],a_2[index 46 } 47 return true; 48 } 49 50 ////////////////////////////////////////////// 51 /// PREC(*a_fabs)(PREC) : //////////////////// 52 ////////////////////////////////////////////// 53 54 // for histo equals functions. 55 56 template <class NUMBER,class PREC> 57 inline bool numbers_are_equal(const NUMBER& a_ 58 NUMBER diff = a_left - a_right; 59 if(a_fabs(diff)>=a_prec) return false; 60 return true; 61 } 62 63 template <class VEC,class PREC> 64 inline bool vectors_are_equal(const VEC& a_1,c 65 if(a_1.size()!=a_2.size()) return false; 66 typedef typename VEC::size_type sz_t; 67 sz_t sz = a_1.size(); 68 //bool status = true; 69 for(sz_t index=0;index<sz;index++) { 70 if(!numbers_are_equal(a_1[index],a_2[index 71 //{ ::printf("debug : vectors_are_equals : 72 return false; 73 //status = false; 74 //} 75 } 76 return true; 77 //return status; 78 } 79 80 template <class VECVEC,class PREC> 81 inline bool vecvecs_are_equal(const VECVEC& a_ 82 if(a_1.size()!=a_2.size()) return false; 83 typedef typename VECVEC::size_type sz_t; 84 sz_t sz = a_1.size(); 85 for(sz_t index=0;index<sz;index++) { 86 if(!vectors_are_equal(a_1[index],a_2[index 87 } 88 return true; 89 } 90 91 ////////////////////////////////////////////// 92 ////////////////////////////////////////////// 93 ////////////////////////////////////////////// 94 95 } 96 97 #endif