summaryrefslogtreecommitdiff
path: root/include/bigint.h
blob: 15da24538ee8d33fb1419cf57d41386a6bf51add (plain)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#ifndef _BIGINT_H
#define _BIGINT_H

#include <cassert>
#include <cstdlib>
#include <iostream>

#include <gmp.h>
//#include <bigrand.h>

using namespace std;

class bigint
{
friend class bigrational;
friend class bigreal;
friend class bigcomplex;
  
  mpz_t rep;
  
  //  constructor, assignment and destructor
  
  bigint(const mpz_t);
  
  //  conversion
  
  double frexp(long*) const;
  
  //  arithmetic
  
  bigint add(const bigint&) const;
  bigint sub(const bigint&) const;
  bigint mul(const bigint&) const;
  bigint div(const bigint&) const;
  
  void inc();
  void dec();
  
  bigint lshift(const unsigned long) const;
  bigint rshift(const unsigned long) const;
  
  bigint neg() const;
  bigint abs() const;
  
  bigint root(const unsigned long) const;
  bigint sqrt() const;
  
  //  comparison
  
  int cmp(const bigint&) const;
  
  int sgn() const;
  
  //  bit
  
  bigint AND(const bigint&) const;
  bigint IOR(const bigint&) const;
  bigint XOR(const bigint&) const;
  
  //  algebra
  
  bigint gcd(const bigint&) const;
  bigint lcm(const bigint&) const;
  
public:
  
  //  constructor, assignment and destructor
  
  bigint();
  bigint(const unsigned int);
  bigint(const signed int);
  bigint(const unsigned long);
  bigint(const signed long);
  bigint(const double);
  bigint(const char*);
  
  bigint(const bigint&);
  bigint& operator =(const bigint&);
  
  ~bigint();
  
  //  random
  
//  friend bigint rand();
  
  //  conversion
  
  unsigned long len() const;
  
  int           fits_long() const;
  long          as_long() const;
  int           fits_unsigned_long() const;
  unsigned long as_unsigned_long() const;
  
  friend double frexp(const bigint&, long*);
  friend long   lb4lgAbs(const bigint&);
  friend long   ub4lgAbs(const bigint&);
  
  //  arithmetic
  
  friend bigint operator +(const bigint&, const bigint&);
  friend bigint operator -(const bigint&, const bigint&);
  friend bigint operator *(const bigint&, const bigint&);
  friend bigint operator /(const bigint&, const bigint&);
  
  bigint& operator ++();     //  prefix
  bigint  operator ++(int);  //  postfix
  bigint& operator --();     //  prefix
  bigint  operator --(int);  //  postfix
  
  friend bigint operator <<(const bigint&, const unsigned long);
  friend bigint operator >>(const bigint&, const unsigned long);
  
  friend bigint operator -(const bigint&);
  friend bigint abs(const bigint&);
  
  friend bigint root(const bigint&, const unsigned long);
  friend bigint sqrt(const bigint&);
  
  //  comparison
  
  friend int operator ==(const bigint&, const bigint&);
  friend int operator !=(const bigint&, const bigint&);
  friend int operator <(const bigint&, const bigint&);
  friend int operator <=(const bigint&, const bigint&);
  friend int operator >(const bigint&, const bigint&);
  friend int operator >=(const bigint&, const bigint&);
  
  friend int sgn(const bigint&);
  friend int operator &&(const bigint&, const bigint&);
  friend int operator ||(const bigint&, const bigint&);
  friend int operator !(const bigint&);
  
  //  bit
  
  friend bigint operator &(const bigint&, const bigint&);
  friend bigint operator |(const bigint&, const bigint&);
  friend bigint operator ^(const bigint&, const bigint&);
  
  int bit(unsigned long) const;
  
  //  algebra
  
  friend bigint gcd(const bigint&, const bigint&);
  friend bigint lcm(const bigint&, const bigint&);
  
  //  arithmetic and assignment
  
  bigint& operator +=(const bigint&);
  bigint& operator -=(const bigint&);
  bigint& operator *=(const bigint&);
  bigint& operator /=(const bigint&);
  
  bigint& operator <<=(const unsigned long);
  bigint& operator >>=(const unsigned long);
  
  bigint& operator &=(const bigint&);
  bigint& operator |=(const bigint&);
  bigint& operator ^=(const bigint&);
  
  //  stream
  
  friend ostream& operator <<(ostream&, const bigint&);
  friend istream& operator >>(istream&, bigint&);
};

#endif