Main Page
Related Pages
Modules
Data Structures
Files
Examples
File List
Globals
libavutil
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 Libav.
6
*
7
* Libav 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
* Libav 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 Libav; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
*/
21
28
#ifndef AVUTIL_RATIONAL_H
29
#define AVUTIL_RATIONAL_H
30
31
#include <stdint.h>
32
#include <limits.h>
33
#include "
attributes.h
"
34
43
typedef
struct
AVRational
{
44
int
num
;
45
int
den
;
46
}
AVRational
;
47
55
static
inline
int
av_cmp_q
(
AVRational
a,
AVRational
b
){
56
const
int64_t tmp= a.
num
* (int64_t)b.
den
- b.
num
* (int64_t)a.
den
;
57
58
if
(tmp)
return
((tmp ^ a.
den
^ b.
den
)>>63)|1;
59
else
if
(b.
den
&& a.
den
)
return
0;
60
else
if
(a.
num
&& b.
num
)
return
(a.
num
>>31) - (b.
num
>>31);
61
else
return
INT_MIN;
62
}
63
69
static
inline
double
av_q2d
(
AVRational
a){
70
return
a.
num
/ (double) a.
den
;
71
}
72
83
int
av_reduce
(
int
*dst_num,
int
*dst_den, int64_t num, int64_t den, int64_t max);
84
91
AVRational
av_mul_q
(
AVRational
b
,
AVRational
c)
av_const
;
92
99
AVRational
av_div_q
(
AVRational
b
,
AVRational
c)
av_const
;
100
107
AVRational
av_add_q
(
AVRational
b
,
AVRational
c)
av_const
;
108
115
AVRational
av_sub_q
(
AVRational
b
,
AVRational
c)
av_const
;
116
125
AVRational
av_d2q
(
double
d,
int
max)
av_const
;
126
131
int
av_nearer_q
(
AVRational
q,
AVRational
q1,
AVRational
q2);
132
138
int
av_find_nearest_q_idx
(
AVRational
q,
const
AVRational
* q_list);
139
144
#endif
/* AVUTIL_RATIONAL_H */