[PATCH 04/14] Add a special case for av_cmp_q() when one of the values to be compared is 0/0.
Stefano Sabatini
stefano.sabatini-lala
Thu Sep 30 21:42:56 CEST 2010
---
libavutil/rational.h | 8 ++++++--
1 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/libavutil/rational.h b/libavutil/rational.h
index 21542a8..f70c1b5 100644
--- a/libavutil/rational.h
+++ b/libavutil/rational.h
@@ -28,6 +28,7 @@
#ifndef AVUTIL_RATIONAL_H
#define AVUTIL_RATIONAL_H
+#include <limits.h>
#include <stdint.h>
#include "attributes.h"
@@ -43,13 +44,16 @@ typedef struct AVRational{
* Compare two rationals.
* @param a first rational
* @param b second rational
- * @return 0 if a==b, 1 if a>b and -1 if a<b
+ * @return 0 if a==b, 1 if a>b, -1 if a<b, and INT_MIN if one of the
+ * values is of the form 0/0
*/
static inline int av_cmp_q(AVRational a, AVRational b){
const int64_t tmp= a.num * (int64_t)b.den - b.num * (int64_t)a.den;
if(tmp) return ((tmp ^ a.den ^ b.den)>>63)|1;
- else return 0;
+ else if (b.den && a.den) return 0;
+ else if (a.num && b.num) return (a.num>>31) - (b.num>>31);
+ else return INT_MIN;
}
/**
--
1.7.1
--NMuMz9nt05w80d4+
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="0005-Add-a-test-for-av_cmp_q.patch"
More information about the ffmpeg-devel
mailing list