Merge branch 'reorganization'
[biginteger-lo27.git] / biginteger.h
blob6ad9a474cedc48d55e3c0cc53431de4e095a4df9
1 /* Copyright (c) 2008 Jérémie Laval, Marine Jourdain
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to deal
5 * in the Software without restriction, including without limitation the rights
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 * copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 * THE SOFTWARE.
23 #ifndef _BIG_INTEGER_H
24 #define _BIG_INTEGER_H
26 // Type declaration
28 #define BASE 10000
30 typedef struct _BigUnsignedInteger {
31 // A coefficient in base 10,000
32 unsigned int Value;
33 // Next coefficient
34 struct _BigUnsignedInteger* Next;
35 // Previous coefficient
36 struct _BigUnsignedInteger* Previous;
38 } BigUnsignedInteger;
41 typedef enum {
42 Negative = -1,
43 Positive = 1,
44 Undefined = 0
46 } Sign;
48 typedef struct {
49 // Restricted to value -1, 0 or 1
50 Sign Sign;
51 // The absolute value which is multiplied by sign to get the real integer value
52 BigUnsignedInteger* AbsValStart; // Head
53 BigUnsignedInteger* AbsValEnd; // Tail
54 int Count;
55 } BigInteger;
58 typedef enum {
59 false = 0,
60 true = 1
61 } Boolean;
63 // End type declaration
65 // Public Functions declaration
67 BigInteger newBigInteger(char*);
69 void printBigInteger(BigInteger);
71 Boolean isNull(BigInteger);
73 int signBigInt(BigInteger);
75 Boolean equalsBigInt(BigInteger, BigInteger);
77 int compareBigInt(BigInteger, BigInteger);
79 BigInteger sumBigInt(BigInteger, BigInteger);
81 BigInteger diffBigInt(BigInteger, BigInteger);
83 BigInteger mulBigInt(BigInteger, BigInteger);
85 BigInteger quotientBigInt(BigInteger, BigInteger);
87 BigInteger restBigInt(BigInteger, BigInteger);
89 BigInteger gcdBigInt(BigInteger, BigInteger);
91 BigInteger lcmBigInt(BigInteger, BigInteger);
93 BigInteger factorial(unsigned long);
95 BigInteger cnp(unsigned long, unsigned long);
97 // End Public Function Declaration
99 #endif