瀏覽代碼

cmVectOps.h,cmVectOpsRIHdr.h,cmVectOpsRICode.h: Added use of generic cmIsClose()

to vector op. IsClose().
master
Kevin Larke 9 年之前
父節點
當前提交
172b562022
共有 3 個文件被更改,包括 8 次插入15 次删除
  1. 3
    1
      vop/cmVectOps.h
  2. 2
    12
      vop/cmVectOpsRICode.h
  3. 3
    2
      vop/cmVectOpsRIHdr.h

+ 3
- 1
vop/cmVectOps.h 查看文件

@@ -104,7 +104,9 @@ cmReal_t cmVOI_Variance(const int* sp, unsigned sn, const cmReal_t* mean);
104 104
 // dbp[1,dn] = v[1,vn] * m[vn,dn]
105 105
 cmComplexR_t* cmVORC_MultVVM( cmComplexR_t* dbp, unsigned dn, const cmComplexR_t* vp, unsigned vn, const cmComplexR_t* m );
106 106
 
107
-
107
+#define cmAbs(x)              _Generic((x),  double:fabs,       float:fabsf,      int:abs,        unsigned:abs,        default:fabs )(x)  
108
+#define cmIsClose(x0,x1,eps)  _Generic((x0), double:cmIsCloseD, float:cmIsCloseF, int:cmIsCloseI, unsigned:cmIsCloseU, default:cmIsCloseD)(x0,x1,eps)
109
+  
108 110
 #ifdef __cplusplus
109 111
 }
110 112
 #endif

+ 2
- 12
vop/cmVectOpsRICode.h 查看文件

@@ -873,22 +873,12 @@ bool VECT_OP_FUNC(IsEqual)( const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, un
873 873
   return true;
874 874
 }
875 875
 
876
-bool VECT_OP_FUNC(IsClose)( const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, unsigned sn, double pct )
876
+bool VECT_OP_FUNC(IsClose)( const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, unsigned sn, double eps )
877 877
 {
878 878
   const VECT_OP_TYPE* ep = s0p + sn;
879 879
   for(; s0p < ep; ++s0p,++s1p )
880 880
   {
881
-    double d = *s1p - *s0p;
882
-    double s = cmMin(*s1p,*s0p);
883
-
884
-    // take abs value of d and s
885
-    if( d < 0 )
886
-      d *= -1;
887
-
888
-    if( s < 0 )
889
-      s *= -1;
890
-
891
-    if( d*100.0/s > pct )
881
+    if( !cmIsClose(*s0p,*s1p,eps) )
892 882
       return false;
893 883
   }
894 884
   return true;

+ 3
- 2
vop/cmVectOpsRIHdr.h 查看文件

@@ -137,8 +137,9 @@ unsigned*  VECT_OP_FUNC(MaxIndexM)( unsigned* dp, const VECT_OP_TYPE* sp, unsign
137 137
 /// Return true if s0p[sn] is equal to s1p[sn]
138 138
 bool       VECT_OP_FUNC(IsEqual)( const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, unsigned sn );
139 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 );
140
+/// Return true if all elements of s0p[sn] are within 'eps' of s1p[sn].
141
+/// This function is based on cmMath.h:cmIsCloseX()
142
+bool VECT_OP_FUNC(IsClose)( const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, unsigned sn, double eps );
142 143
 
143 144
 /// Return the most frequently occuring element in sp.
144 145
 VECT_OP_TYPE  VECT_OP_FUNC(Mode)(     const VECT_OP_TYPE* sp, unsigned sn );

Loading…
取消
儲存