debian/tmp/usr/include/libavutil/rational.h
Go to the documentation of this file.
00001 /*
00002  * rational numbers
00003  * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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 
00043 typedef struct AVRational{
00044     int num; 
00045     int den; 
00046 } AVRational;
00047 
00055 static inline int av_cmp_q(AVRational a, AVRational b){
00056     const int64_t tmp= a.num * (int64_t)b.den - b.num * (int64_t)a.den;
00057 
00058     if(tmp) return ((tmp ^ a.den ^ b.den)>>63)|1;
00059     else if(b.den && a.den) return 0;
00060     else if(a.num && b.num) return (a.num>>31) - (b.num>>31);
00061     else                    return INT_MIN;
00062 }
00063 
00069 static inline double av_q2d(AVRational a){
00070     return a.num / (double) a.den;
00071 }
00072 
00083 int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max);
00084 
00091 AVRational av_mul_q(AVRational b, AVRational c) av_const;
00092 
00099 AVRational av_div_q(AVRational b, AVRational c) av_const;
00100 
00107 AVRational av_add_q(AVRational b, AVRational c) av_const;
00108 
00115 AVRational av_sub_q(AVRational b, AVRational c) av_const;
00116 
00125 AVRational av_d2q(double d, int max) av_const;
00126 
00131 int av_nearer_q(AVRational q, AVRational q1, AVRational q2);
00132 
00138 int av_find_nearest_q_idx(AVRational q, const AVRational* q_list);
00139 
00144 #endif /* AVUTIL_RATIONAL_H */