Miam-Player  0.8.0
A nice music player
rational.h
Go to the documentation of this file.
1 /*
2  * rational numbers
3  * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
29 #ifndef AVUTIL_RATIONAL_H
30 #define AVUTIL_RATIONAL_H
31 
32 #include <stdint.h>
33 #include <limits.h>
34 #include "attributes.h"
35 
58 typedef struct AVRational{
59  int num;
60  int den;
61 } AVRational;
62 
71 static inline AVRational av_make_q(int num, int den)
72 {
73  AVRational r = { num, den };
74  return r;
75 }
76 
89 static inline int av_cmp_q(AVRational a, AVRational b){
90  const int64_t tmp= a.num * (int64_t)b.den - b.num * (int64_t)a.den;
91 
92  if(tmp) return (int)((tmp ^ a.den ^ b.den)>>63)|1;
93  else if(b.den && a.den) return 0;
94  else if(a.num && b.num) return (a.num>>31) - (b.num>>31);
95  else return INT_MIN;
96 }
97 
104 static inline double av_q2d(AVRational a){
105  return a.num / (double) a.den;
106 }
107 
120 int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max);
121 
129 
137 
145 
153 
159 static av_always_inline AVRational av_inv_q(AVRational q)
160 {
161  AVRational r = { q.den, q.num };
162  return r;
163 }
164 
176 AVRational av_d2q(double d, int max) av_const;
177 
189 
197 int av_find_nearest_q_idx(AVRational q, const AVRational* q_list);
198 
208 uint32_t av_q2intfloat(AVRational q);
209 
214 #endif /* AVUTIL_RATIONAL_H */
#define av_const
Definition: attributes.h:78
AVRational av_div_q(AVRational b, AVRational c) av_const
uint32_t av_q2intfloat(AVRational q)
AVRational av_sub_q(AVRational b, AVRational c) av_const
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
int num
Numerator.
Definition: rational.h:59
int av_find_nearest_q_idx(AVRational q, const AVRational *q_list)
Definition: rational.h:58
int den
Denominator.
Definition: rational.h:60
AVRational av_d2q(double d, int max) av_const
AVRational av_add_q(AVRational b, AVRational c) av_const
int av_nearer_q(AVRational q, AVRational q1, AVRational q2)
AVRational av_mul_q(AVRational b, AVRational c) av_const
struct AVRational AVRational
#define av_always_inline
Definition: attributes.h:43