summaryrefslogtreecommitdiff
path: root/libavutil/integer.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavutil/integer.c')
-rw-r--r--libavutil/integer.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/libavutil/integer.c b/libavutil/integer.c
index 38a826f861..b0e766f781 100644
--- a/libavutil/integer.c
+++ b/libavutil/integer.c
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
-
+
/**
* @file integer.c
* arbitrary precision integers.
@@ -29,7 +29,7 @@
AVInteger av_add_i(AVInteger a, AVInteger b){
int i, carry=0;
-
+
for(i=0; i<AV_INTEGER_SIZE; i++){
carry= (carry>>16) + a.v[i] + b.v[i];
a.v[i]= carry;
@@ -39,7 +39,7 @@ AVInteger av_add_i(AVInteger a, AVInteger b){
AVInteger av_sub_i(AVInteger a, AVInteger b){
int i, carry=0;
-
+
for(i=0; i<AV_INTEGER_SIZE; i++){
carry= (carry>>16) + a.v[i] - b.v[i];
a.v[i]= carry;
@@ -66,12 +66,12 @@ AVInteger av_mul_i(AVInteger a, AVInteger b){
int i, j;
int na= (av_log2_i(a)+16) >> 4;
int nb= (av_log2_i(b)+16) >> 4;
-
+
memset(&out, 0, sizeof(out));
-
+
for(i=0; i<na; i++){
unsigned int carry=0;
-
+
if(a.v[i])
for(j=i; j<AV_INTEGER_SIZE && j-i<=nb; j++){
carry= (carry>>16) + out.v[j] + a.v[i]*b.v[j-i];
@@ -86,10 +86,10 @@ AVInteger av_mul_i(AVInteger a, AVInteger b){
* returns 0 if a==b, 1 if a>b and -1 if a<b.
*/
int av_cmp_i(AVInteger a, AVInteger b){
- int i;
+ int i;
int v= (int16_t)a.v[AV_INTEGER_SIZE-1] - (int16_t)b.v[AV_INTEGER_SIZE-1];
if(v) return (v>>16)|1;
-
+
for(i=AV_INTEGER_SIZE-2; i>=0; i--){
int v= a.v[i] - b.v[i];
if(v) return (v>>16)|1;
@@ -123,13 +123,13 @@ AVInteger av_mod_i(AVInteger *quot, AVInteger a, AVInteger b){
int i= av_log2_i(a) - av_log2_i(b);
AVInteger quot_temp;
if(!quot) quot = &quot_temp;
-
+
assert((int16_t)a[AV_INTEGER_SIZE-1] >= 0 && (int16_t)b[AV_INTEGER_SIZE-1] >= 0);
assert(av_log2(b)>=0);
-
+
if(i > 0)
b= av_shr_i(b, -i);
-
+
memset(quot, 0, sizeof(AVInteger));
while(i-- >= 0){
@@ -158,7 +158,7 @@ AVInteger av_div_i(AVInteger a, AVInteger b){
AVInteger av_int2i(int64_t a){
AVInteger out;
int i;
-
+
for(i=0; i<AV_INTEGER_SIZE; i++){
out.v[i]= a;
a>>=16;
@@ -168,13 +168,13 @@ AVInteger av_int2i(int64_t a){
/**
* converts the given AVInteger to an int64_t.
- * if the AVInteger is too large to fit into an int64_t,
+ * if the AVInteger is too large to fit into an int64_t,
* then only the least significant 64bit will be used
*/
int64_t av_i2int(AVInteger a){
int i;
int64_t out=(int8_t)a.v[AV_INTEGER_SIZE-1];
-
+
for(i= AV_INTEGER_SIZE-2; i>=0; i--){
out = (out<<16) + a.v[i];
}
@@ -203,7 +203,7 @@ main(){
for(b=3; b<256*256*256; b+=27118){
AVInteger ai= av_int2i(a);
AVInteger bi= av_int2i(b);
-
+
assert(av_i2int(ai) == a);
assert(av_i2int(bi) == b);
assert(av_i2int(av_add_i(ai,bi)) == a+b);