diff --git a/vop/cmVectOps.h b/vop/cmVectOps.h index 13a0c7a..2b85053 100644 --- a/vop/cmVectOps.h +++ b/vop/cmVectOps.h @@ -104,7 +104,9 @@ cmReal_t cmVOI_Variance(const int* sp, unsigned sn, const cmReal_t* mean); // dbp[1,dn] = v[1,vn] * m[vn,dn] cmComplexR_t* cmVORC_MultVVM( cmComplexR_t* dbp, unsigned dn, const cmComplexR_t* vp, unsigned vn, const cmComplexR_t* m ); - +#define cmAbs(x) _Generic((x), double:fabs, float:fabsf, int:abs, unsigned:abs, default:fabs )(x) +#define cmIsClose(x0,x1,eps) _Generic((x0), double:cmIsCloseD, float:cmIsCloseF, int:cmIsCloseI, unsigned:cmIsCloseU, default:cmIsCloseD)(x0,x1,eps) + #ifdef __cplusplus } #endif diff --git a/vop/cmVectOpsRICode.h b/vop/cmVectOpsRICode.h index 99ec57a..8630345 100644 --- a/vop/cmVectOpsRICode.h +++ b/vop/cmVectOpsRICode.h @@ -873,22 +873,12 @@ bool VECT_OP_FUNC(IsEqual)( const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, un return true; } -bool VECT_OP_FUNC(IsClose)( const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, unsigned sn, double pct ) +bool VECT_OP_FUNC(IsClose)( const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, unsigned sn, double eps ) { const VECT_OP_TYPE* ep = s0p + sn; for(; s0p < ep; ++s0p,++s1p ) { - double d = *s1p - *s0p; - double s = cmMin(*s1p,*s0p); - - // take abs value of d and s - if( d < 0 ) - d *= -1; - - if( s < 0 ) - s *= -1; - - if( d*100.0/s > pct ) + if( !cmIsClose(*s0p,*s1p,eps) ) return false; } return true; diff --git a/vop/cmVectOpsRIHdr.h b/vop/cmVectOpsRIHdr.h index 24c716b..9227004 100644 --- a/vop/cmVectOpsRIHdr.h +++ b/vop/cmVectOpsRIHdr.h @@ -137,8 +137,9 @@ unsigned* VECT_OP_FUNC(MaxIndexM)( unsigned* dp, const VECT_OP_TYPE* sp, unsign /// Return true if s0p[sn] is equal to s1p[sn] bool VECT_OP_FUNC(IsEqual)( const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, unsigned sn ); -/// Return true if all elements of s0p[sn] are within 'pct' percent of s1p[sn]. -bool VECT_OP_FUNC(IsClose)( const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, unsigned sn, double pct ); +/// Return true if all elements of s0p[sn] are within 'eps' of s1p[sn]. +/// This function is based on cmMath.h:cmIsCloseX() +bool VECT_OP_FUNC(IsClose)( const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, unsigned sn, double eps ); /// Return the most frequently occuring element in sp. VECT_OP_TYPE VECT_OP_FUNC(Mode)( const VECT_OP_TYPE* sp, unsigned sn );