libavutil/integer.h
29adde83
 /*
  * arbitrary precision integers
  * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
  *
b78e7197
  * This file is part of FFmpeg.
  *
  * FFmpeg is free software; you can redistribute it and/or
29adde83
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
b78e7197
  * version 2.1 of the License, or (at your option) any later version.
29adde83
  *
b78e7197
  * FFmpeg is distributed in the hope that it will be useful,
29adde83
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
b78e7197
  * License along with FFmpeg; if not, write to the Free Software
5509bffa
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29adde83
  */
115329f1
 
29adde83
 /**
ba87f080
  * @file
29adde83
  * arbitrary precision integers
  * @author Michael Niedermayer <michaelni@gmx.at>
  */
115329f1
 
98790382
 #ifndef AVUTIL_INTEGER_H
 #define AVUTIL_INTEGER_H
29adde83
 
99545457
 #include <stdint.h>
3540b950
 #include "common.h"
99545457
 
29adde83
 #define AV_INTEGER_SIZE 8
 
 typedef struct AVInteger{
115329f1
     uint16_t v[AV_INTEGER_SIZE];
29adde83
 } AVInteger;
 
85074d3c
 AVInteger av_add_i(AVInteger a, AVInteger b) av_const;
 AVInteger av_sub_i(AVInteger a, AVInteger b) av_const;
395722ba
 
 /**
49bd8e4b
  * Return the rounded-down value of the base 2 logarithm of the given
7d685b48
  * AVInteger. This is simply the index of the most significant bit
  * which is 1, or 0 if all bits are 0.
395722ba
  */
85074d3c
 int av_log2_i(AVInteger a) av_const;
 AVInteger av_mul_i(AVInteger a, AVInteger b) av_const;
fb7d4f79
 
 /**
49bd8e4b
  * Return 0 if a==b, 1 if a>b and -1 if a<b.
fb7d4f79
  */
85074d3c
 int av_cmp_i(AVInteger a, AVInteger b) av_const;
886368e9
 
 /**
89c9ff50
  * bitwise shift
  * @param s the number of bits by which the value should be shifted right,
             may be negative for shifting left
886368e9
  */
85074d3c
 AVInteger av_shr_i(AVInteger a, int s) av_const;
607da27c
 
 /**
49bd8e4b
  * Return a % b.
89c9ff50
  * @param quot a/b will be stored here.
607da27c
  */
29adde83
 AVInteger av_mod_i(AVInteger *quot, AVInteger a, AVInteger b);
9375cdd5
 
 /**
49bd8e4b
  * Return a/b.
9375cdd5
  */
85074d3c
 AVInteger av_div_i(AVInteger a, AVInteger b) av_const;
c1f56787
 
 /**
49bd8e4b
  * Convert the given int64_t to an AVInteger.
c1f56787
  */
85074d3c
 AVInteger av_int2i(int64_t a) av_const;
37b2f1d0
 
 /**
49bd8e4b
  * Convert the given AVInteger to an int64_t.
bfe3676f
  * If the AVInteger is too large to fit into an int64_t,
  * then only the least significant 64 bits will be used.
37b2f1d0
  */
85074d3c
 int64_t av_i2int(AVInteger a) av_const;
29adde83
 
98790382
 #endif /* AVUTIL_INTEGER_H */