-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBigInteger.h
66 lines (46 loc) · 1.77 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
#ifndef BIG_INTEGER
#define BIG_INTEGER
#include "MyList.h"
//#include <list>
/*
* The BigInteger class is used to represent integers larger than 2^31.
* It manages to do this by storing one digit in each 'element' of the list.
* Do not edit this file.
* Make your own BigInteger.cpp file.
*/
class BigIntException: public exception
{
public:
virtual const char * what() const throw()
{
return "Enter a string only numeric characters!";
}
};
class BigInteger
{
private:
// test with this for modular testing (also uncomment above):
// If you leave it in for submission, you will get a 0.
//std::list<int> digit_list;
MyList<int> digit_list;
bool isNegative;
public:
BigInteger();
BigInteger(std::string really_big_number);
// make const next year!
std::string to_string();
// Speed tested for bonus points.
// https://en.wikipedia.org/wiki/Primality_test
bool is_prime();
friend BigInteger operator+(const BigInteger &bi1, const BigInteger &bi2);
friend BigInteger operator-(const BigInteger &bi1, const BigInteger &bi2);
friend BigInteger operator*(const BigInteger &bi1, const BigInteger &bi2);
friend BigInteger operator/(const BigInteger &bi1, const BigInteger &bi2);
// Recursion is a good idea from here down, especiall for speed on the exp:
// Speed tested for bonus points.
friend BigInteger gcd(const BigInteger dividend, const BigInteger divisor);
// Speed tested for bonus points.
// We made this a friend to allow use of recursion.
friend BigInteger gefficient_exp(const BigInteger base, long long power);
};
#endif