Statistics
| Branch: | Revision:

ffmpeg / libavcodec / rational.h @ 20646267

History | View | Annotate | Download (1.57 KB)

1 5ff85f1d Michael Niedermayer
/*
2
 * Rational numbers
3
 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Lesser General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 2 of the License, or (at your option) any later version.
9
 *
10
 * This library is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * Lesser General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Lesser General Public
16
 * License along with this library; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 *
19
 */
20
 
21
/**
22
 * @file rational.h
23
 * Rational numbers.
24
 * @author Michael Niedermayer <michaelni@gmx.at>
25
 */
26
27
#ifndef RATIONAL_H
28
#define RATIONAL_H
29
30
typedef struct AVRational{
31
    int num; 
32
    int den;
33
} AVRational;
34
35
static inline int av_cmp_q(AVRational a, AVRational b){
36
    const int64_t tmp= a.num * (int64_t)b.den - b.num * (int64_t)a.den;
37
38
    if     (tmp <  0) return -1;
39
    else if(tmp == 0) return  0;
40
    else              return  1;
41
}
42
43
static inline double av_q2d(AVRational a){
44
    return a.num / (double) a.den;
45
}
46
47
AVRational av_mul_q(AVRational b, AVRational c);
48
AVRational av_div_q(AVRational b, AVRational c);
49
AVRational av_add_q(AVRational b, AVRational c);
50
AVRational av_sub_q(AVRational b, AVRational c);
51
AVRational av_d2q(double d, int max);
52
53
#endif // RATIONAL_H