]> git.sesse.net Git - ffmpeg/blobdiff - libavutil/mathematics.c
Silence "comparison of unsigned expression >= 0 is always true" warning.
[ffmpeg] / libavutil / mathematics.c
index 9988baae9c543cb36634a8cfed414d34e5680dd2..c6851cb755ea2877acdd57856dd30e55cfe7f5d7 100644 (file)
  */
 
 /**
- * @file libavutil/mathematics.c
+ * @file
  * miscellaneous math routines and tables
  */
 
 #include <assert.h>
-#include "avutil.h"
-#include "common.h"
+#include <stdint.h>
+#include <limits.h>
 #include "mathematics.h"
 
 const uint8_t ff_sqrt_tab[256]={
@@ -78,7 +78,7 @@ int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd){
     int64_t r=0;
     assert(c > 0);
     assert(b >=0);
-    assert(rnd >=0 && rnd<=5 && rnd!=4);
+    assert((unsigned)rnd<=5 && rnd!=4);
 
     if(a<0 && a != INT64_MIN) return -av_rescale_rnd(-a, b, c, rnd ^ ((rnd>>1)&1));
 
@@ -136,6 +136,21 @@ int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq){
     return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF);
 }
 
+int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b){
+    int64_t a= tb_a.num * (int64_t)tb_b.den;
+    int64_t b= tb_b.num * (int64_t)tb_a.den;
+    if (av_rescale_rnd(ts_a, a, b, AV_ROUND_DOWN) < ts_b) return -1;
+    if (av_rescale_rnd(ts_b, b, a, AV_ROUND_DOWN) < ts_a) return  1;
+    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