-
Notifications
You must be signed in to change notification settings - Fork 125
Expand file tree
/
Copy pathBigInt.hpp
More file actions
109 lines (95 loc) · 3.93 KB
/
BigInt.hpp
File metadata and controls
109 lines (95 loc) · 3.93 KB
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
109
/*
===========================================================================
BigInt
===========================================================================
Definition for the BigInt class.
*/
#ifndef BIG_INT_HPP
#define BIG_INT_HPP
#include <iostream>
#include <vector>
class BigInt {
std::vector<unsigned long long> magnitude;
bool is_negative;
public:
// Constructors:
BigInt();
BigInt(const BigInt&);
BigInt(const long long&);
BigInt(const std::string&);
// Assignment operators:
BigInt& operator=(const BigInt&);
BigInt& operator=(const long long&);
BigInt& operator=(const std::string&);
// Unary arithmetic operators:
BigInt operator+() const; // unary +
BigInt operator-() const; // unary -
// Binary arithmetic operators:
BigInt operator+(const BigInt&) const;
BigInt operator-(const BigInt&) const;
BigInt operator*(const BigInt&) const;
BigInt operator/(const BigInt&) const;
BigInt operator%(const BigInt&) const;
BigInt operator+(const long long&) const;
BigInt operator-(const long long&) const;
BigInt operator*(const long long&) const;
BigInt operator/(const long long&) const;
BigInt operator%(const long long&) const;
BigInt operator+(const std::string&) const;
BigInt operator-(const std::string&) const;
BigInt operator*(const std::string&) const;
BigInt operator/(const std::string&) const;
BigInt operator%(const std::string&) const;
// Arithmetic-assignment operators:
BigInt& operator+=(const BigInt&);
BigInt& operator-=(const BigInt&);
BigInt& operator*=(const BigInt&);
BigInt& operator/=(const BigInt&);
BigInt& operator%=(const BigInt&);
BigInt& operator+=(const long long&);
BigInt& operator-=(const long long&);
BigInt& operator*=(const long long&);
BigInt& operator/=(const long long&);
BigInt& operator%=(const long long&);
BigInt& operator+=(const std::string&);
BigInt& operator-=(const std::string&);
BigInt& operator*=(const std::string&);
BigInt& operator/=(const std::string&);
BigInt& operator%=(const std::string&);
// Increment and decrement operators:
BigInt& operator++(); // pre-increment
BigInt& operator--(); // pre-decrement
BigInt operator++(int); // post-increment
BigInt operator--(int); // post-decrement
// Relational operators:
bool operator<(const BigInt&) const;
bool operator>(const BigInt&) const;
bool operator<=(const BigInt&) const;
bool operator>=(const BigInt&) const;
bool operator==(const BigInt&) const;
bool operator!=(const BigInt&) const;
bool operator<(const long long&) const;
bool operator>(const long long&) const;
bool operator<=(const long long&) const;
bool operator>=(const long long&) const;
bool operator==(const long long&) const;
bool operator!=(const long long&) const;
bool operator<(const std::string&) const;
bool operator>(const std::string&) const;
bool operator<=(const std::string&) const;
bool operator>=(const std::string&) const;
bool operator==(const std::string&) const;
bool operator!=(const std::string&) const;
// I/O stream operators:
friend std::istream& operator>>(std::istream&, BigInt&);
friend std::ostream& operator<<(std::ostream&, const BigInt&);
// Conversion functions:
std::string to_string() const;
int to_int() const;
long to_long() const;
long long to_long_long() const;
std::std::vector<uint64_t> to_base64();
// Random number generating functions:
friend BigInt big_random(size_t);
};
#endif // BIG_INT_HPP