Преглед изворни кода

cmVectOpsRIHdr/Code.h: Added cmVoX_IsEqual() and cmVoX_IsClose().

master
kevin пре 11 година
родитељ
комит
44c4ad31fe
2 измењених фајлова са 27 додато и 0 уклоњено
  1. 22
    0
      vop/cmVectOpsRICode.h
  2. 5
    0
      vop/cmVectOpsRIHdr.h

+ 22
- 0
vop/cmVectOpsRICode.h Прегледај датотеку

@@ -864,6 +864,28 @@ unsigned*  VECT_OP_FUNC(MaxIndexM)( unsigned* dp, const VECT_OP_TYPE* sp, unsign
864 864
   return dp;
865 865
 }
866 866
 
867
+bool VECT_OP_FUNC(IsEqual)( const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, unsigned sn )
868
+{
869
+  const VECT_OP_TYPE* ep = s0p + sn;
870
+  for(; s0p < ep; ++s0p,++s1p )
871
+    if( *s0p != *s1p )
872
+      return false;
873
+  return true;
874
+}
875
+
876
+bool VECT_OP_FUNC(IsClose)( const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, unsigned sn, double pct )
877
+{
878
+  const VECT_OP_TYPE* ep = s0p + sn;
879
+  for(; s0p < ep; ++s0p,++s1p )
880
+  {
881
+    double d = abs(*s1p - *s0p);
882
+    double s = cmMin(*s1p,*s0p);
883
+    if( d*100.0/s > pct )
884
+      return false;
885
+  }
886
+  return true;
887
+}
888
+
867 889
 
868 890
 VECT_OP_TYPE  VECT_OP_FUNC(Mode)( const VECT_OP_TYPE* sp, unsigned sn )
869 891
 {

+ 5
- 0
vop/cmVectOpsRIHdr.h Прегледај датотеку

@@ -134,6 +134,11 @@ VECT_OP_TYPE*  VECT_OP_FUNC(MaxVV)( VECT_OP_TYPE* dp, unsigned dn, const VECT_OP
134 134
 unsigned*  VECT_OP_FUNC(MinIndexM)( unsigned* dp, const VECT_OP_TYPE* sp, unsigned srn, unsigned scn );
135 135
 unsigned*  VECT_OP_FUNC(MaxIndexM)( unsigned* dp, const VECT_OP_TYPE* sp, unsigned srn, unsigned scn );
136 136
 
137
+/// Return true if s0p[sn] is equal to s1p[sn]
138
+bool       VECT_OP_FUNC(IsEqual)( const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, unsigned sn );
139
+
140
+/// Return true if all elements of s0p[sn] are within 'pct' percent of s1p[sn].
141
+bool VECT_OP_FUNC(IsClose)( const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, unsigned sn, double pct );
137 142
 
138 143
 /// Return the most frequently occuring element in sp.
139 144
 VECT_OP_TYPE  VECT_OP_FUNC(Mode)(     const VECT_OP_TYPE* sp, unsigned sn );

Loading…
Откажи
Сачувај