1cabdff1aSopenharmony_ci/*
2cabdff1aSopenharmony_ci * arbitrary precision integers
3cabdff1aSopenharmony_ci * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
4cabdff1aSopenharmony_ci *
5cabdff1aSopenharmony_ci * This file is part of FFmpeg.
6cabdff1aSopenharmony_ci *
7cabdff1aSopenharmony_ci * FFmpeg is free software; you can redistribute it and/or
8cabdff1aSopenharmony_ci * modify it under the terms of the GNU Lesser General Public
9cabdff1aSopenharmony_ci * License as published by the Free Software Foundation; either
10cabdff1aSopenharmony_ci * version 2.1 of the License, or (at your option) any later version.
11cabdff1aSopenharmony_ci *
12cabdff1aSopenharmony_ci * FFmpeg is distributed in the hope that it will be useful,
13cabdff1aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
14cabdff1aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15cabdff1aSopenharmony_ci * Lesser General Public License for more details.
16cabdff1aSopenharmony_ci *
17cabdff1aSopenharmony_ci * You should have received a copy of the GNU Lesser General Public
18cabdff1aSopenharmony_ci * License along with FFmpeg; if not, write to the Free Software
19cabdff1aSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20cabdff1aSopenharmony_ci */
21cabdff1aSopenharmony_ci
22cabdff1aSopenharmony_ci/**
23cabdff1aSopenharmony_ci * @file
24cabdff1aSopenharmony_ci * arbitrary precision integers
25cabdff1aSopenharmony_ci * @author Michael Niedermayer <michaelni@gmx.at>
26cabdff1aSopenharmony_ci */
27cabdff1aSopenharmony_ci
28cabdff1aSopenharmony_ci#ifndef AVUTIL_INTEGER_H
29cabdff1aSopenharmony_ci#define AVUTIL_INTEGER_H
30cabdff1aSopenharmony_ci
31cabdff1aSopenharmony_ci#include <stdint.h>
32cabdff1aSopenharmony_ci#include "attributes.h"
33cabdff1aSopenharmony_ci
34cabdff1aSopenharmony_ci#define AV_INTEGER_SIZE 8
35cabdff1aSopenharmony_ci
36cabdff1aSopenharmony_citypedef struct AVInteger{
37cabdff1aSopenharmony_ci    uint16_t v[AV_INTEGER_SIZE];
38cabdff1aSopenharmony_ci} AVInteger;
39cabdff1aSopenharmony_ci
40cabdff1aSopenharmony_ciAVInteger av_add_i(AVInteger a, AVInteger b) av_const;
41cabdff1aSopenharmony_ciAVInteger av_sub_i(AVInteger a, AVInteger b) av_const;
42cabdff1aSopenharmony_ci
43cabdff1aSopenharmony_ci/**
44cabdff1aSopenharmony_ci * Return the rounded-down value of the base 2 logarithm of the given
45cabdff1aSopenharmony_ci * AVInteger. This is simply the index of the most significant bit
46cabdff1aSopenharmony_ci * which is 1, or 0 if all bits are 0.
47cabdff1aSopenharmony_ci */
48cabdff1aSopenharmony_ciint av_log2_i(AVInteger a) av_const;
49cabdff1aSopenharmony_ciAVInteger av_mul_i(AVInteger a, AVInteger b) av_const;
50cabdff1aSopenharmony_ci
51cabdff1aSopenharmony_ci/**
52cabdff1aSopenharmony_ci * Return 0 if a==b, 1 if a>b and -1 if a<b.
53cabdff1aSopenharmony_ci */
54cabdff1aSopenharmony_ciint av_cmp_i(AVInteger a, AVInteger b) av_const;
55cabdff1aSopenharmony_ci
56cabdff1aSopenharmony_ci/**
57cabdff1aSopenharmony_ci * bitwise shift
58cabdff1aSopenharmony_ci * @param s the number of bits by which the value should be shifted right,
59cabdff1aSopenharmony_ci            may be negative for shifting left
60cabdff1aSopenharmony_ci */
61cabdff1aSopenharmony_ciAVInteger av_shr_i(AVInteger a, int s) av_const;
62cabdff1aSopenharmony_ci
63cabdff1aSopenharmony_ci/**
64cabdff1aSopenharmony_ci * Return a % b.
65cabdff1aSopenharmony_ci * @param quot a/b will be stored here.
66cabdff1aSopenharmony_ci */
67cabdff1aSopenharmony_ciAVInteger av_mod_i(AVInteger *quot, AVInteger a, AVInteger b);
68cabdff1aSopenharmony_ci
69cabdff1aSopenharmony_ci/**
70cabdff1aSopenharmony_ci * Return a/b.
71cabdff1aSopenharmony_ci */
72cabdff1aSopenharmony_ciAVInteger av_div_i(AVInteger a, AVInteger b) av_const;
73cabdff1aSopenharmony_ci
74cabdff1aSopenharmony_ci/**
75cabdff1aSopenharmony_ci * Convert the given int64_t to an AVInteger.
76cabdff1aSopenharmony_ci */
77cabdff1aSopenharmony_ciAVInteger av_int2i(int64_t a) av_const;
78cabdff1aSopenharmony_ci
79cabdff1aSopenharmony_ci/**
80cabdff1aSopenharmony_ci * Convert the given AVInteger to an int64_t.
81cabdff1aSopenharmony_ci * If the AVInteger is too large to fit into an int64_t,
82cabdff1aSopenharmony_ci * then only the least significant 64 bits will be used.
83cabdff1aSopenharmony_ci */
84cabdff1aSopenharmony_ciint64_t av_i2int(AVInteger a) av_const;
85cabdff1aSopenharmony_ci
86cabdff1aSopenharmony_ci#endif /* AVUTIL_INTEGER_H */
87