From 44c4ad31fe7a1fe29f4bb64acf1168efecdab572 Mon Sep 17 00:00:00 2001
From: kevin <kpl@larke.org>
Date: Thu, 21 Mar 2013 08:39:26 -0700
Subject: [PATCH] cmVectOpsRIHdr/Code.h: Added cmVoX_IsEqual() and
 cmVoX_IsClose().

---
 vop/cmVectOpsRICode.h | 22 ++++++++++++++++++++++
 vop/cmVectOpsRIHdr.h  |  5 +++++
 2 files changed, 27 insertions(+)

diff --git a/vop/cmVectOpsRICode.h b/vop/cmVectOpsRICode.h
index 4d74398..91d2e09 100644
--- a/vop/cmVectOpsRICode.h
+++ b/vop/cmVectOpsRICode.h
@@ -864,6 +864,28 @@ unsigned*  VECT_OP_FUNC(MaxIndexM)( unsigned* dp, const VECT_OP_TYPE* sp, unsign
   return dp;
 }
 
+bool VECT_OP_FUNC(IsEqual)( const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, unsigned sn )
+{
+  const VECT_OP_TYPE* ep = s0p + sn;
+  for(; s0p < ep; ++s0p,++s1p )
+    if( *s0p != *s1p )
+      return false;
+  return true;
+}
+
+bool VECT_OP_FUNC(IsClose)( const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, unsigned sn, double pct )
+{
+  const VECT_OP_TYPE* ep = s0p + sn;
+  for(; s0p < ep; ++s0p,++s1p )
+  {
+    double d = abs(*s1p - *s0p);
+    double s = cmMin(*s1p,*s0p);
+    if( d*100.0/s > pct )
+      return false;
+  }
+  return true;
+}
+
 
 VECT_OP_TYPE  VECT_OP_FUNC(Mode)( const VECT_OP_TYPE* sp, unsigned sn )
 {
diff --git a/vop/cmVectOpsRIHdr.h b/vop/cmVectOpsRIHdr.h
index 4bdaab5..24c716b 100644
--- a/vop/cmVectOpsRIHdr.h
+++ b/vop/cmVectOpsRIHdr.h
@@ -134,6 +134,11 @@ VECT_OP_TYPE*  VECT_OP_FUNC(MaxVV)( VECT_OP_TYPE* dp, unsigned dn, const VECT_OP
 unsigned*  VECT_OP_FUNC(MinIndexM)( unsigned* dp, const VECT_OP_TYPE* sp, unsigned srn, unsigned scn );
 unsigned*  VECT_OP_FUNC(MaxIndexM)( unsigned* dp, const VECT_OP_TYPE* sp, unsigned srn, unsigned scn );
 
+/// 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 the most frequently occuring element in sp.
 VECT_OP_TYPE  VECT_OP_FUNC(Mode)(     const VECT_OP_TYPE* sp, unsigned sn );