00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00028 #ifndef AVUTIL_RATIONAL_H
00029 #define AVUTIL_RATIONAL_H
00030 
00031 #include <stdint.h>
00032 #include <limits.h>
00033 #include "attributes.h"
00034 
00038 typedef struct AVRational{
00039     int num; 
00040     int den; 
00041 } AVRational;
00042 
00050 static inline int av_cmp_q(AVRational a, AVRational b){
00051     const int64_t tmp= a.num * (int64_t)b.den - b.num * (int64_t)a.den;
00052 
00053     if(tmp) return ((tmp ^ a.den ^ b.den)>>63)|1;
00054     else if(b.den && a.den) return 0;
00055     else if(a.num && b.num) return (a.num>>31) - (b.num>>31);
00056     else                    return INT_MIN;
00057 }
00058 
00064 static inline double av_q2d(AVRational a){
00065     return a.num / (double) a.den;
00066 }
00067 
00078 int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max);
00079 
00086 AVRational av_mul_q(AVRational b, AVRational c) av_const;
00087 
00094 AVRational av_div_q(AVRational b, AVRational c) av_const;
00095 
00102 AVRational av_add_q(AVRational b, AVRational c) av_const;
00103 
00110 AVRational av_sub_q(AVRational b, AVRational c) av_const;
00111 
00120 AVRational av_d2q(double d, int max) av_const;
00121 
00126 int av_nearer_q(AVRational q, AVRational q1, AVRational q2);
00127 
00133 int av_find_nearest_q_idx(AVRational q, const AVRational* q_list);
00134 
00135 #endif