1 /*
2 * arbitrary precision integers
3 * Copyright (c) 2004 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
22 /**
23 * @file
24 * arbitrary precision integers
25 * @author Michael Niedermayer <michaelni@gmx.at>
26 */
27
31
33
35 int i, carry=0;
36
38 carry= (carry>>16) + a.
v[i] + b.
v[i];
40 }
42 }
43
45 int i, carry=0;
46
48 carry= (carry>>16) + a.
v[i] - b.
v[i];
50 }
52 }
53
55 int i;
56
60 }
61 return -1;
62 }
63
66 int i, j;
69
70 memset(&out, 0, sizeof(out));
71
72 for(i=0; i<na; i++){
73 unsigned int carry=0;
74
77 carry= (carry>>16) + out.
v[j] + a.
v[i]*b.
v[j-i];
79 }
80 }
81
83 }
84
86 int i;
88 if(v) return (v>>16)|1;
89
91 int v= a.
v[i] - b.
v[i];
92 if(v) return (v>>16)|1;
93 }
94 return 0;
95 }
96
99 int i;
100
102 unsigned int index= i + (s>>4);
103 unsigned int v=0;
104 if(index+1<AV_INTEGER_SIZE) v = a.
v[index+1]<<16;
105 if(index <AV_INTEGER_SIZE) v+= a.
v[
index ];
106 out.
v[i]= v >> (s&15);
107 }
109 }
110
114 if(!quot) quot = "_temp;
115
120 }
121
124
125 if(i > 0)
127
129
130 while(i-- >= 0){
135 }
137 }
139 }
140
144 return quot;
145 }
146
149 int i;
150
153 a>>=16;
154 }
156 }
157
159 int i;
161
163 out = (out<<16) + a.
v[i];
164 }
166 }
167
168 #ifdef TEST
169
171 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
172 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
173 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
174 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
175 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
176 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
177 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
178 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
179 };
180
183
184 for(a=7; a<256*256*256; a+=13215){
185 for(b=3; b<256*256*256; b+=27118){
188
200 }
201 }
202 return 0;
203 }
204 #endif
int av_log2_16bit(unsigned v)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
uint16_t v[AV_INTEGER_SIZE]
int64_t av_i2int(AVInteger a)
Convert the given AVInteger to an int64_t.
AVInteger av_int2i(int64_t a)
Convert the given int64_t to an AVInteger.
int av_log2_i(AVInteger a)
Return the rounded-down value of the base 2 logarithm of the given AVInteger.
AVInteger av_mul_i(AVInteger a, AVInteger b)
simple assert() macros that are a bit more flexible than ISO C assert().
int av_cmp_i(AVInteger a, AVInteger b)
Return 0 if a==b, 1 if a>b and -1 if a<b.
AVInteger av_add_i(AVInteger a, AVInteger b)
const uint8_t ff_log2_tab[256]
static const AVInteger zero_i
AVInteger av_sub_i(AVInteger a, AVInteger b)
AVInteger av_shr_i(AVInteger a, int s)
bitwise shift
arbitrary precision integers
AVInteger av_mod_i(AVInteger *quot, AVInteger a, AVInteger b)
Return a % b.
common internal and external API header
AVInteger av_div_i(AVInteger a, AVInteger b)
Return a/b.
int main(int argc, char **argv)