-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbig_integer_gmp.h
90 lines (70 loc) · 3.21 KB
/
big_integer_gmp.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
#ifndef BIG_INTEGER_GMP_H
#define BIG_INTEGER_GMP_H
#include <cstddef>
#include <gmp.h>
#include <iosfwd>
struct big_integer_gmp {
big_integer_gmp();
big_integer_gmp(big_integer_gmp const& other);
big_integer_gmp(int a);
explicit big_integer_gmp(std::string const& str);
template<typename RNG>
big_integer_gmp& random(size_t sz, RNG&& rng) {
gmp_randstate_t state;
gmp_randinit_mt(state);
gmp_randseed_ui(state, rng());
mpz_urandomb(mpz, state, sz + 1);
gmp_randclear(state);
big_integer_gmp shift(1);
shift <<= sz;
*this -= shift;
return *this;
}
~big_integer_gmp();
big_integer_gmp& operator=(big_integer_gmp const& other);
big_integer_gmp& operator+=(big_integer_gmp const& rhs);
big_integer_gmp& operator-=(big_integer_gmp const& rhs);
big_integer_gmp& operator*=(big_integer_gmp const& rhs);
big_integer_gmp& operator/=(big_integer_gmp const& rhs);
big_integer_gmp& operator%=(big_integer_gmp const& rhs);
big_integer_gmp& operator&=(big_integer_gmp const& rhs);
big_integer_gmp& operator|=(big_integer_gmp const& rhs);
big_integer_gmp& operator^=(big_integer_gmp const& rhs);
big_integer_gmp& operator<<=(int rhs);
big_integer_gmp& operator>>=(int rhs);
big_integer_gmp operator+() const;
big_integer_gmp operator-() const;
big_integer_gmp operator~() const;
big_integer_gmp& operator++();
big_integer_gmp operator++(int);
big_integer_gmp& operator--();
big_integer_gmp operator--(int);
friend bool operator==(big_integer_gmp const& a, big_integer_gmp const& b);
friend bool operator!=(big_integer_gmp const& a, big_integer_gmp const& b);
friend bool operator<(big_integer_gmp const& a, big_integer_gmp const& b);
friend bool operator>(big_integer_gmp const& a, big_integer_gmp const& b);
friend bool operator<=(big_integer_gmp const& a, big_integer_gmp const& b);
friend bool operator>=(big_integer_gmp const& a, big_integer_gmp const& b);
friend std::string to_string(big_integer_gmp const& a);
private:
mpz_t mpz;
};
big_integer_gmp operator+(big_integer_gmp a, big_integer_gmp const& b);
big_integer_gmp operator-(big_integer_gmp a, big_integer_gmp const& b);
big_integer_gmp operator*(big_integer_gmp a, big_integer_gmp const& b);
big_integer_gmp operator/(big_integer_gmp a, big_integer_gmp const& b);
big_integer_gmp operator%(big_integer_gmp a, big_integer_gmp const& b);
big_integer_gmp operator&(big_integer_gmp a, big_integer_gmp const& b);
big_integer_gmp operator|(big_integer_gmp a, big_integer_gmp const& b);
big_integer_gmp operator^(big_integer_gmp a, big_integer_gmp const& b);
big_integer_gmp operator<<(big_integer_gmp a, int b);
big_integer_gmp operator>>(big_integer_gmp a, int b);
bool operator==(big_integer_gmp const& a, big_integer_gmp const& b);
bool operator!=(big_integer_gmp const& a, big_integer_gmp const& b);
bool operator<(big_integer_gmp const& a, big_integer_gmp const& b);
bool operator>(big_integer_gmp const& a, big_integer_gmp const& b);
bool operator<=(big_integer_gmp const& a, big_integer_gmp const& b);
bool operator>=(big_integer_gmp const& a, big_integer_gmp const& b);
std::string to_string(big_integer_gmp const& a);
std::ostream& operator<<(std::ostream& s, big_integer_gmp const& a);
#endif // BIG_INTEGER_GMP_H