World of Might and Magic  0.2.0
Open reimplementation of Might and Magic 6 7 8 game engine
rational.h
См. документацию.
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 
209 
214 #endif /* AVUTIL_RATIONAL_H */
av_div_q
AVRational av_div_q(AVRational b, AVRational c) av_const
av_sub_q
AVRational av_sub_q(AVRational b, AVRational c) av_const
q
GLdouble GLdouble GLdouble GLdouble q
Definition: SDL_opengl.h:2087
av_q2intfloat
uint32_t av_q2intfloat(AVRational q)
int64_t
__int64 int64_t
Definition: alext.h:31
num
GLuint num
Definition: SDL_opengl_glext.h:4959
av_reduce
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
av_q2d
static double av_q2d(AVRational a)
Definition: rational.h:104
AVRational
struct AVRational AVRational
av_make_q
static AVRational av_make_q(int num, int den)
Definition: rational.h:71
attributes.h
av_find_nearest_q_idx
int av_find_nearest_q_idx(AVRational q, const AVRational *q_list)
av_d2q
AVRational av_d2q(double d, int max) av_const
b
GLboolean GLboolean GLboolean b
Definition: SDL_opengl_glext.h:1112
av_inv_q
static av_always_inline AVRational av_inv_q(AVRational q)
Definition: rational.h:159
r
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
av_cmp_q
static int av_cmp_q(AVRational a, AVRational b)
Definition: rational.h:89
c
const GLubyte * c
Definition: SDL_opengl_glext.h:11096
AVRational::num
int num
Numerator.
Definition: rational.h:59
a
GLboolean GLboolean GLboolean GLboolean a
Definition: SDL_opengl_glext.h:1112
av_mul_q
AVRational av_mul_q(AVRational b, AVRational c) av_const
AVRational
Definition: rational.h:58
av_nearer_q
int av_nearer_q(AVRational q, AVRational q1, AVRational q2)
av_add_q
AVRational av_add_q(AVRational b, AVRational c) av_const
uint32_t
unsigned __int32 uint32_t
Definition: SDL_config.h:39
AVRational::den
int den
Denominator.
Definition: rational.h:60