forked from technophilis/BigIntegerCPP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BigInteger.h
95 lines (76 loc) · 3.28 KB
/
BigInteger.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* BigInteger Class, performs basic arithmetic operations of very large integers.
* Copyright (C) 2011 Mahmoud Mechehoul
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef BIGINT_H_
#define BIGINT_H_
#include <iostream>
using namespace std;
class BigInteger {
private:
string integer;
public:
/* Constructs a big integer representation of the integer given as an argument */
BigInteger(unsigned int integer);
/* Parses the string given as an argument looking for an integer.
* Stops as soon as it finds a non-digit character.
* Trailing zeros will eventually get removed.
*/
BigInteger(string integer);
/* Constructs a big integer representation of the integer given as an argument
* and assigns it to the internal representation of the big integer.
*/
void setInteger(unsigned int integer);
/* Parses the string given as an argument looking for an integer and assigns it to
* the internal representation of the big integer.
* Stops as soon as it finds a non-digit character.
* Trailing zeros will eventually get removed.
*/
void setInteger(string integer);
/* Returns 0 if the value of the internal big integer won't fit in 32 bits.
* Otherwise it returns the integer values.
*/
unsigned int getIntValue() const;
/* Returns the internal big integer as a string */
string toString() const;
/* Adds the big integer given as an argument to the internal big integer
* and returns the result as a string.
*/
BigInteger addInteger(const BigInteger& integer_to_add) const;
/* Adds the integer represented by the string given as an argument to the internal
* big integer and returns the result as a string.
*/
BigInteger addInteger(const string& integer_to_add) const;
/* Multiplies the big integer given as an argument by the internal big integer
* and returns the result as a string.
*/
BigInteger multiplyInteger(const BigInteger& integer_to_multiply) const;
/* Multiplies the integer represented by the string given as an argument by the internal
* big integer and returns the result as a string.
*/
BigInteger multiplyInteger(const string& integer_to_multiply) const;
/* Returns the index of the first non-zero digit in the string given as an argument.
* This function is used to trim trailing zeros from a string representation of an integer.
* A trimmed version of the string is a substring that starts at the index returned by this
* function.
*/
static size_t getTrimIndex(const string& integer);
bool operator==(const BigInteger& integer) const;
BigInteger operator+(const BigInteger& integer) const;
BigInteger operator*(const BigInteger& integer) const;
friend ostream& operator<<(ostream& in, BigInteger& integer);
};
#endif /* BIGINT_H_ */