changeset 933:93bd29f34e99 libavutil

Add av_compare_mod()
author michael
date Wed, 09 Jun 2010 17:27:42 +0000
parents be49bac1a894
children 252d7a7ee7d5
files mathematics.c mathematics.h
diffstat 2 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mathematics.c	Sat Jun 05 12:01:28 2010 +0000
+++ b/mathematics.c	Wed Jun 09 17:27:42 2010 +0000
@@ -144,6 +144,13 @@
     return 0;
 }
 
+int64_t av_compare_mod(uint64_t a, uint64_t b, uint64_t mod){
+    int64_t c= (a-b) & (mod-1);
+    if(c > (mod>>1))
+        c-= mod;
+    return c;
+}
+
 #ifdef TEST
 #include "integer.h"
 #undef printf
--- a/mathematics.h	Sat Jun 05 12:01:28 2010 +0000
+++ b/mathematics.h	Wed Jun 09 17:27:42 2010 +0000
@@ -94,5 +94,14 @@
  */
 int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b);
 
+/**
+ * Compare 2 integers modulo mod.
+ * That is we compare integers a and b for which only the least significant log2(mod) bits are known
+ * @param mod must be a power of 2
+ * @returns a negative value if a is smaller than b
+ *          a positiv  value if a is greater than b
+ *          0                if a equals          b
+ */
+int64_t av_compare_mod(uint64_t a, uint64_t b, uint64_t mod);
 
 #endif /* AVUTIL_MATHEMATICS_H */