g4tools  5.4.0
eqT
Go to the documentation of this file.
1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
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_left,const NUMBER& a_right,const PREC& a_prec,PREC(*a_fabs)(const NUMBER&)) {
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 PREC& a_prec,PREC(*a_fabs)(const NUMBER&)) {
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,const VEC& a_2,const PREC& a_prec,PREC(*a_fabs)(const PREC&)) {
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],a_prec,a_fabs))
30  //{ ::printf("debug : vectors_are_equals : %lu : %g %g\n",index,a_1[index],a_2[index]);
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_1,const VECVEC& a_2,const PREC& a_prec,PREC(*a_fabs)(const PREC&)) {
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],a_prec,a_fabs)) return false;
46  }
47  return true;
48 }
49 
53 
54 // for histo equals functions.
55 
56 template <class NUMBER,class PREC>
57 inline bool numbers_are_equal(const NUMBER& a_left,const NUMBER& a_right,const PREC& a_prec,PREC(*a_fabs)(NUMBER)) {
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,const VEC& a_2,const PREC& a_prec,PREC(*a_fabs)(PREC)) {
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],a_prec,a_fabs))
71  //{ ::printf("debug : vectors_are_equals : %lu : %g %g\n",index,a_1[index],a_2[index]);
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_1,const VECVEC& a_2,const PREC& a_prec,PREC(*a_fabs)(PREC)) {
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],a_prec,a_fabs)) return false;
87  }
88  return true;
89 }
90 
94 
95 }
96 
97 #endif
tools::vecvecs_are_equal
bool vecvecs_are_equal(const VECVEC &a_1, const VECVEC &a_2, const PREC &a_prec, PREC(*a_fabs)(const PREC &))
Definition: eqT:40
tools::vectors_are_equal
bool vectors_are_equal(const VEC &a_1, const VEC &a_2, const PREC &a_prec, PREC(*a_fabs)(const PREC &))
Definition: eqT:23
tools::is_zero
bool is_zero(const NUMBER &a_left, const PREC &a_prec, PREC(*a_fabs)(const NUMBER &))
Definition: eqT:17
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::diff
void diff(std::ostream &a_out, const array< T > &aA, const array< T > &aB, T a_epsilon)
Definition: array:529
tools::numbers_are_equal
bool numbers_are_equal(const NUMBER &a_left, const NUMBER &a_right, const PREC &a_prec, PREC(*a_fabs)(const NUMBER &))
Definition: eqT:10