comparison integer.c @ 2127:2c2f738772b7 libavcodec

more comments
author michael
date Thu, 15 Jul 2004 14:06:39 +0000
parents 7523553ca85f
children
comparison
equal deleted inserted replaced
2126:181cb6785f6b 2127:2c2f738772b7
45 a.v[i]= carry; 45 a.v[i]= carry;
46 } 46 }
47 return a; 47 return a;
48 } 48 }
49 49
50 /**
51 * returns the rounded down value of the logarithm of base 2 of the given AVInteger.
52 * this is simply the index of the most significant bit which is 1. Or 0 of all bits are 0
53 */
50 int av_log2_i(AVInteger a){ 54 int av_log2_i(AVInteger a){
51 int i; 55 int i;
52 56
53 for(i=AV_INTEGER_SIZE-1; i>=0; i--){ 57 for(i=AV_INTEGER_SIZE-1; i>=0; i--){
54 if(a.v[i]) 58 if(a.v[i])
76 } 80 }
77 81
78 return out; 82 return out;
79 } 83 }
80 84
85 /**
86 * returns 0 if a==b, 1 if a>b and -1 if a<b.
87 */
81 int av_cmp_i(AVInteger a, AVInteger b){ 88 int av_cmp_i(AVInteger a, AVInteger b){
82 int i; 89 int i;
83 int v= (int16_t)a.v[AV_INTEGER_SIZE-1] - (int16_t)b.v[AV_INTEGER_SIZE-1]; 90 int v= (int16_t)a.v[AV_INTEGER_SIZE-1] - (int16_t)b.v[AV_INTEGER_SIZE-1];
84 if(v) return (v>>16)|1; 91 if(v) return (v>>16)|1;
85 92
88 if(v) return (v>>16)|1; 95 if(v) return (v>>16)|1;
89 } 96 }
90 return 0; 97 return 0;
91 } 98 }
92 99
100 /**
101 * bitwise shift.
102 * @param s the number of bits by which the value should be shifted right, may be negative for shifting left
103 */
93 AVInteger av_shr_i(AVInteger a, int s){ 104 AVInteger av_shr_i(AVInteger a, int s){
94 AVInteger out; 105 AVInteger out;
95 int i; 106 int i;
96 107
97 for(i=0; i<AV_INTEGER_SIZE; i++){ 108 for(i=0; i<AV_INTEGER_SIZE; i++){
102 out.v[i]= v >> (s&15); 113 out.v[i]= v >> (s&15);
103 } 114 }
104 return out; 115 return out;
105 } 116 }
106 117
118 /**
119 * returns a % b.
120 * @param quot a/b will be stored here
121 */
107 AVInteger av_mod_i(AVInteger *quot, AVInteger a, AVInteger b){ 122 AVInteger av_mod_i(AVInteger *quot, AVInteger a, AVInteger b){
108 int i= av_log2_i(a) - av_log2_i(b); 123 int i= av_log2_i(a) - av_log2_i(b);
109 AVInteger quot_temp; 124 AVInteger quot_temp;
110 if(!quot) quot = &quot_temp; 125 if(!quot) quot = &quot_temp;
111 126
126 b= av_shr_i(b, 1); 141 b= av_shr_i(b, 1);
127 } 142 }
128 return a; 143 return a;
129 } 144 }
130 145
146 /**
147 * returns a/b.
148 */
131 AVInteger av_div_i(AVInteger a, AVInteger b){ 149 AVInteger av_div_i(AVInteger a, AVInteger b){
132 AVInteger quot; 150 AVInteger quot;
133 av_mod_i(&quot, a, b); 151 av_mod_i(&quot, a, b);
134 return quot; 152 return quot;
135 } 153 }
136 154
155 /**
156 * converts the given int64_t to an AVInteger.
157 */
137 AVInteger av_int2i(int64_t a){ 158 AVInteger av_int2i(int64_t a){
138 AVInteger out; 159 AVInteger out;
139 int i; 160 int i;
140 161
141 for(i=0; i<AV_INTEGER_SIZE; i++){ 162 for(i=0; i<AV_INTEGER_SIZE; i++){
143 a>>=16; 164 a>>=16;
144 } 165 }
145 return out; 166 return out;
146 } 167 }
147 168
169 /**
170 * converts the given AVInteger to an int64_t.
171 * if the AVInteger is too large to fit into an int64_t,
172 * then only the least significant 64bit will be used
173 */
148 int64_t av_i2int(AVInteger a){ 174 int64_t av_i2int(AVInteger a){
149 int i; 175 int i;
150 int64_t out=(int8_t)a.v[AV_INTEGER_SIZE-1]; 176 int64_t out=(int8_t)a.v[AV_INTEGER_SIZE-1];
151 177
152 for(i= AV_INTEGER_SIZE-2; i>=0; i--){ 178 for(i= AV_INTEGER_SIZE-2; i>=0; i--){