-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBigNumber.h
108 lines (59 loc) · 2.61 KB
/
BigNumber.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
96
97
98
99
100
101
102
103
104
105
106
107
108
#ifndef TA14_BIGNUMBER_H
#define TA14_BIGNUMBER_H
#include <cstdint>
#include <string>
#include <regex>
class BigNumber {
friend std::ostream &operator<<(std::ostream &output, const BigNumber &myBig);
friend std::istream &operator>>(std::istream &input, BigNumber &myBig);
friend BigNumber operator+(const BigNumber &num1, const BigNumber &num2);
friend BigNumber operator-(const BigNumber &num1, const BigNumber &num2);
protected:
unsigned numOfDigits;
bool validate(const std::string &str, const std::string &pattern);
unsigned numOfTrimCharsOnLeft(const std::string &str);
BigNumber() {}
int8_t &operator[](size_t index);
//max(a, b) a.max(b)
bool sign;
int8_t *numArray = nullptr;
public:
//must be private
static BigNumber unsignedMax(const BigNumber &num1, const BigNumber &num2);
static BigNumber unsignedMin(const BigNumber &num1, const BigNumber &num2);
static bool unsignedGreaterOrEqual(const BigNumber &num1, const BigNumber &num2);
static bool unsignedLessOrEqual(const BigNumber &num1, const BigNumber &num2);
static BigNumber unsignedAdd(const BigNumber &num1, const BigNumber &num2);
static BigNumber unsignedSubtract(const BigNumber &num1, const BigNumber &num2);
// end of private list
BigNumber(const std::string &str);
BigNumber(const char *myCharArray) : BigNumber((std::string) myCharArray) {}
BigNumber(const long &intNum);
BigNumber(const BigNumber &myBig); // copy constructor
BigNumber(BigNumber &&myBig) noexcept; // move constructor
~BigNumber();
void setValues(const std::string &str);
bool getSign() const;
void setSign(bool signNew);
unsigned int getNumOfDigits() const;
BigNumber &operator=(const BigNumber &rightNum);
BigNumber &operator=(BigNumber &&rightNum) noexcept; // move assignment overloading
BigNumber operator-() const;
int operator[](size_t index) const;
bool operator==(const BigNumber &myBig) const;
bool operator!=(const BigNumber &myBig) const;
bool operator>=(const BigNumber &myBig) const;
bool operator<=(const BigNumber &myBig) const;
bool operator>(const BigNumber &myBig) const;
bool operator<(const BigNumber &myBig) const;
BigNumber absoluteValue() const;
BigNumber operator>>(unsigned shift);
BigNumber &operator--();
BigNumber operator--(int);
BigNumber &operator++();
BigNumber operator++(int);
BigNumber &operator+=(const BigNumber &num1);
BigNumber &operator-=(const BigNumber &num1);
virtual std::string to_string() const;
};
#endif //TA14_BIGNUMBER_H