*sumBigInt implementation
[biginteger-lo27.git] / biginteger.h
blobe729429e0d6e02a4cd893de8549130aed3b73738
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
55 } BigInteger;
58 typedef enum {
59 false = 0,
60 true = 1
61 } Boolean;
63 // End type declaration
66 // Private Function Declaration
68 BigUnsignedInteger* ReturnNthNode(BigInteger*, int);
70 BigInteger CreateZeroBigInt();
72 BigUnsignedInteger* InitBUint(unsigned int);
74 void PrependNode(BigUnsignedInteger*, BigUnsignedInteger*);
76 void PushFrontNode(BigInteger*, unsigned int);
78 void PushEndNode(BigInteger*, unsigned int);
80 void InsertNode(BigInteger*, BigUnsignedInteger*, unsigned int);
82 // End Private Function Declaration
85 // Public Functions declaration
87 BigInteger newBigInteger(char*);
89 void printBigInteger(BigInteger);
91 Boolean isNull(BigInteger);
93 int signBigInt(BigInteger);
95 Boolean equalsBigInt(BigInteger, BigInteger);
97 int compareBigInt(BigInteger, BigInteger);
99 BigInteger sumBigInt(BigInteger, BigInteger);
101 BigInteger diffBigInt(BigInteger, BigInteger);
103 BigInteger mulBigInt(BigInteger, BigInteger);
105 BigInteger quotientBigInt(BigInteger, BigInteger);
107 BigInteger restBigInt(BigInteger, BigInteger);
109 BigInteger gcdBigInt(BigInteger, BigInteger);
111 BigInteger lcmBigInt(BigInteger, BigInteger);
113 BigInteger factorial(unsigned long);
115 BigInteger cnp(unsigned long, unsigned long);
117 // End Public Function Declaration
119 #endif