1 // This may look like C code, but it is really -*- C++ -*-
4 Copyright (C) 1988 Free Software Foundation
5 written by Doug Lea (dl@rocky.oswego.edu)
7 This file is part of GNU CC.
9 GNU CC is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY. No author or distributor
11 accepts responsibility to anyone for the consequences of using it
12 or for whether it serves any particular purpose or works at all,
13 unless he says so in writing. Refer to the GNU CC General Public
14 License for full details.
16 Everyone is granted permission to copy, modify and redistribute
17 GNU CC, but only under the conditions described in the
18 GNU CC General Public License. A copy of this license is
19 supposed to have been given to you along with GNU CC so you
20 can know your rights and responsibilities. It should be in a
21 file named COPYING. Among other things, the copyright notice
22 and this notice must be preserved on all copies.
34 struct IntRep
// internal Integer representations
36 unsigned short len
; // current length
37 unsigned short sz
; // allocated space
38 short sgn
; // 1 means >= 0; 0 means < 0
39 unsigned short s
[1]; // represented as ushort array starting here
42 extern IntRep
* Ialloc(IntRep
*, const unsigned short *, int, int, int);
43 extern IntRep
* Icalloc(IntRep
*, int);
44 extern IntRep
* Icopy_long(IntRep
*, long);
45 extern IntRep
* Icopy(IntRep
*, const IntRep
*);
46 extern IntRep
* Iresize(IntRep
*, int);
47 extern IntRep
* add(const IntRep
*, int, const IntRep
*, int, IntRep
*);
48 extern IntRep
* add(const IntRep
*, int, long, IntRep
*);
49 extern IntRep
* multiply(const IntRep
*, const IntRep
*, IntRep
*);
50 extern IntRep
* multiply(const IntRep
*, long, IntRep
*);
51 extern IntRep
* lshift(const IntRep
*, long, IntRep
*);
52 extern IntRep
* lshift(const IntRep
*, const IntRep
*, int, IntRep
*);
53 extern IntRep
* bitop(const IntRep
*, const IntRep
*, IntRep
*, char);
54 extern IntRep
* bitop(const IntRep
*, long, IntRep
*, char);
55 extern IntRep
* power(const IntRep
*, long, IntRep
*);
56 extern IntRep
* div(const IntRep
*, const IntRep
*, IntRep
*);
57 extern IntRep
* mod(const IntRep
*, const IntRep
*, IntRep
*);
58 extern IntRep
* div(const IntRep
*, long, IntRep
*);
59 extern IntRep
* mod(const IntRep
*, long, IntRep
*);
60 extern IntRep
* compl(const IntRep
*, IntRep
*);
61 extern IntRep
* abs(const IntRep
*, IntRep
*);
62 extern IntRep
* negate(const IntRep
*, IntRep
*);
63 extern IntRep
* pow(const IntRep
*, long);
64 extern IntRep
* gcd(const IntRep
*, const IntRep
* y
);
65 extern int compare(const IntRep
*, const IntRep
*);
66 extern int compare(const IntRep
*, long);
67 extern int ucompare(const IntRep
*, const IntRep
*);
68 extern int ucompare(const IntRep
*, long);
69 extern char* Itoa(const IntRep
* x
, int base
= 10, int width
= 0);
70 extern IntRep
* atoIntRep(const char* s
, int base
= 10);
71 extern long Itolong(const IntRep
*);
72 extern double Itodouble(const IntRep
*);
73 extern int Iislong(const IntRep
*);
74 extern int Iisdouble(const IntRep
*);
75 extern long lg(const IntRep
*);
85 Integer(const Integer
&);
89 void operator = (const Integer
&);
90 void operator = (long);
92 // unary operations to self
96 void negate(); // negate in-place
97 void abs(); // absolute-value in-place
98 void complement(); // bitwise complement in-place
100 // assignment-based operations
102 void operator += (const Integer
&);
103 void operator -= (const Integer
&);
104 void operator *= (const Integer
&);
105 void operator /= (const Integer
&);
106 void operator %= (const Integer
&);
107 void operator <<=(const Integer
&);
108 void operator >>=(const Integer
&);
109 void operator &= (const Integer
&);
110 void operator |= (const Integer
&);
111 void operator ^= (const Integer
&);
113 void operator += (long);
114 void operator -= (long);
115 void operator *= (long);
116 void operator /= (long);
117 void operator %= (long);
118 void operator <<=(long);
119 void operator >>=(long);
120 void operator &= (long);
121 void operator |= (long);
122 void operator ^= (long);
124 // (constructive binary operations are inlined below)
127 friend Integer
operator <? (const Integer
& x
, const Integer
& y
); // min
128 friend Integer
operator >? (const Integer
& x
, const Integer
& y
); // max
131 // builtin Integer functions that must be friends
133 friend long lg (const Integer
&); // floor log base 2 of abs(x)
134 friend double ratio(const Integer
& x
, const Integer
& y
);
135 // return x/y as a double
137 friend Integer
gcd(const Integer
&, const Integer
&);
138 friend int even(const Integer
&); // true if even
139 friend int odd(const Integer
&); // true if odd
140 friend int sign(const Integer
&); // returns -1, 0, +1
142 friend void setbit(Integer
& x
, long b
); // set b'th bit of x
143 friend void clearbit(Integer
& x
, long b
); // clear b'th bit
144 friend int testbit(const Integer
& x
, long b
); // return b'th bit
146 // procedural versions of operators
148 friend void abs(const Integer
& x
, Integer
& dest
);
149 friend void negate(const Integer
& x
, Integer
& dest
);
150 friend void complement(const Integer
& x
, Integer
& dest
);
152 friend int compare(const Integer
&, const Integer
&);
153 friend int ucompare(const Integer
&, const Integer
&);
154 friend void add(const Integer
& x
, const Integer
& y
, Integer
& dest
);
155 friend void sub(const Integer
& x
, const Integer
& y
, Integer
& dest
);
156 friend void mul(const Integer
& x
, const Integer
& y
, Integer
& dest
);
157 friend void div(const Integer
& x
, const Integer
& y
, Integer
& dest
);
158 friend void mod(const Integer
& x
, const Integer
& y
, Integer
& dest
);
159 friend void divide(const Integer
& x
, const Integer
& y
,
160 Integer
& q
, Integer
& r
);
161 friend void and(const Integer
& x
, const Integer
& y
, Integer
& dest
);
162 friend void or(const Integer
& x
, const Integer
& y
, Integer
& dest
);
163 friend void xor(const Integer
& x
, const Integer
& y
, Integer
& dest
);
164 friend void lshift(const Integer
& x
, const Integer
& y
, Integer
& dest
);
165 friend void rshift(const Integer
& x
, const Integer
& y
, Integer
& dest
);
166 friend void pow(const Integer
& x
, const Integer
& y
, Integer
& dest
);
168 friend int compare(const Integer
&, long);
169 friend int ucompare(const Integer
&, long);
170 friend void add(const Integer
& x
, long y
, Integer
& dest
);
171 friend void sub(const Integer
& x
, long y
, Integer
& dest
);
172 friend void mul(const Integer
& x
, long y
, Integer
& dest
);
173 friend void div(const Integer
& x
, long y
, Integer
& dest
);
174 friend void mod(const Integer
& x
, long y
, Integer
& dest
);
175 friend void divide(const Integer
& x
, long y
, Integer
& q
, long& r
);
176 friend void and(const Integer
& x
, long y
, Integer
& dest
);
177 friend void or(const Integer
& x
, long y
, Integer
& dest
);
178 friend void xor(const Integer
& x
, long y
, Integer
& dest
);
179 friend void lshift(const Integer
& x
, long y
, Integer
& dest
);
180 friend void rshift(const Integer
& x
, long y
, Integer
& dest
);
181 friend void pow(const Integer
& x
, long y
, Integer
& dest
);
183 friend int compare(long, const Integer
&);
184 friend int ucompare(long, const Integer
&);
185 friend void add(long x
, const Integer
& y
, Integer
& dest
);
186 friend void sub(long x
, const Integer
& y
, Integer
& dest
);
187 friend void mul(long x
, const Integer
& y
, Integer
& dest
);
188 friend void and(long x
, const Integer
& y
, Integer
& dest
);
189 friend void or(long x
, const Integer
& y
, Integer
& dest
);
190 friend void xor(long x
, const Integer
& y
, Integer
& dest
);
192 // coercion & conversion
194 int fits_in_long() const;
195 int fits_in_double() const;
197 operator long() const;
198 operator double() const;
200 friend char* Itoa(const Integer
& x
, int base
= 10, int width
= 0);
201 friend Integer
atoI(const char* s
, int base
= 10);
203 friend istream
& operator >> (istream
& s
, Integer
& y
);
204 friend ostream
& operator << (ostream
& s
, const Integer
& y
);
208 int initialized() const;
209 volatile void error(const char* msg
) const;
214 // (These are declared inline)
216 int operator == (const Integer
&, const Integer
&);
217 int operator == (const Integer
&, long);
218 int operator != (const Integer
&, const Integer
&);
219 int operator != (const Integer
&, long);
220 int operator < (const Integer
&, const Integer
&);
221 int operator < (const Integer
&, long);
222 int operator <= (const Integer
&, const Integer
&);
223 int operator <= (const Integer
&, long);
224 int operator > (const Integer
&, const Integer
&);
225 int operator > (const Integer
&, long);
226 int operator >= (const Integer
&, const Integer
&);
227 int operator >= (const Integer
&, long);
228 Integer
operator - (const Integer
&);
229 Integer
operator ~ (const Integer
&);
230 Integer
operator + (const Integer
&, const Integer
&);
231 Integer
operator + (const Integer
&, long);
232 Integer
operator + (long, const Integer
&);
233 Integer
operator - (const Integer
&, const Integer
&);
234 Integer
operator - (const Integer
&, long);
235 Integer
operator - (long, const Integer
&);
236 Integer
operator * (const Integer
&, const Integer
&);
237 Integer
operator * (const Integer
&, long);
238 Integer
operator * (long, const Integer
&);
239 Integer
operator / (const Integer
&, const Integer
&);
240 Integer
operator / (const Integer
&, long);
241 Integer
operator % (const Integer
&, const Integer
&);
242 Integer
operator % (const Integer
&, long);
243 Integer
operator << (const Integer
&, const Integer
&);
244 Integer
operator << (const Integer
&, long);
245 Integer
operator >> (const Integer
&, const Integer
&);
246 Integer
operator >> (const Integer
&, long);
247 Integer
operator & (const Integer
&, const Integer
&);
248 Integer
operator & (const Integer
&, long);
249 Integer
operator & (long, const Integer
&);
250 Integer
operator | (const Integer
&, const Integer
&);
251 Integer
operator | (const Integer
&, long);
252 Integer
operator | (long, const Integer
&);
253 Integer
operator ^ (const Integer
&, const Integer
&);
254 Integer
operator ^ (const Integer
&, long);
255 Integer
operator ^ (long, const Integer
&);
257 Integer
abs(const Integer
&); // absolute value
258 Integer
sqr(const Integer
&); // square
260 Integer
pow(const Integer
& x
, const Integer
& y
);
261 Integer
pow(const Integer
& x
, long y
);
262 Integer
Ipow(long x
, long y
); // x to the y as Integer
265 extern char* dec(const Integer
& x
, int width
= 0);
266 extern char* oct(const Integer
& x
, int width
= 0);
267 extern char* hex(const Integer
& x
, int width
= 0);
268 extern Integer
sqrt(const Integer
&); // floor of square root
269 extern Integer
lcm(const Integer
& x
, const Integer
& y
); // least common mult
272 typedef Integer IntTmp
; // for backward compatibility
274 #if defined(__OPTIMIZE__) || defined(USE_LIBGXX_INLINES)
277 inline Integer::Integer() :rep(0) {}
279 inline Integer::Integer(long y
) :rep(Icopy_long(0, y
)) {}
281 inline Integer::Integer(const Integer
& y
) :rep(Icopy(0, y
.rep
)) {}
283 inline Integer::~Integer() { delete rep
; }
285 inline void Integer::operator = (const Integer
& y
)
287 rep
= Icopy(rep
, y
.rep
);
290 inline void Integer::operator = (long y
)
292 rep
= Icopy_long(rep
, y
);
295 inline Integer::operator long() const
300 inline int Integer::initialized() const
305 inline int Integer::fits_in_long() const
310 inline Integer::operator double() const
312 return Itodouble(rep
);
315 inline int Integer::fits_in_double() const
317 return Iisdouble(rep
);
320 // procedural versions
322 inline int compare(const Integer
& x
, const Integer
& y
)
324 return compare(x
.rep
, y
.rep
);
327 inline int ucompare(const Integer
& x
, const Integer
& y
)
329 return ucompare(x
.rep
, y
.rep
);
332 inline int compare(const Integer
& x
, long y
)
334 return compare(x
.rep
, y
);
337 inline int ucompare(const Integer
& x
, long y
)
339 return ucompare(x
.rep
, y
);
342 inline int compare(long x
, const Integer
& y
)
344 return -compare(y
.rep
, x
);
347 inline int ucompare(long x
, const Integer
& y
)
349 return -ucompare(y
.rep
, x
);
352 inline void add(const Integer
& x
, const Integer
& y
, Integer
& dest
)
354 dest
.rep
= add(x
.rep
, 0, y
.rep
, 0, dest
.rep
);
357 inline void sub(const Integer
& x
, const Integer
& y
, Integer
& dest
)
359 dest
.rep
= add(x
.rep
, 0, y
.rep
, 1, dest
.rep
);
362 inline void mul(const Integer
& x
, const Integer
& y
, Integer
& dest
)
364 dest
.rep
= multiply(x
.rep
, y
.rep
, dest
.rep
);
367 inline void div(const Integer
& x
, const Integer
& y
, Integer
& dest
)
369 dest
.rep
= div(x
.rep
, y
.rep
, dest
.rep
);
372 inline void mod(const Integer
& x
, const Integer
& y
, Integer
& dest
)
374 dest
.rep
= mod(x
.rep
, y
.rep
, dest
.rep
);
377 inline void and(const Integer
& x
, const Integer
& y
, Integer
& dest
)
379 dest
.rep
= bitop(x
.rep
, y
.rep
, dest
.rep
, '&');
382 inline void or(const Integer
& x
, const Integer
& y
, Integer
& dest
)
384 dest
.rep
= bitop(x
.rep
, y
.rep
, dest
.rep
, '|');
387 inline void xor(const Integer
& x
, const Integer
& y
, Integer
& dest
)
389 dest
.rep
= bitop(x
.rep
, y
.rep
, dest
.rep
, '^');
392 inline void lshift(const Integer
& x
, const Integer
& y
, Integer
& dest
)
394 dest
.rep
= lshift(x
.rep
, y
.rep
, 0, dest
.rep
);
397 inline void rshift(const Integer
& x
, const Integer
& y
, Integer
& dest
)
399 dest
.rep
= lshift(x
.rep
, y
.rep
, 1, dest
.rep
);
402 inline void pow(const Integer
& x
, const Integer
& y
, Integer
& dest
)
404 dest
.rep
= power(x
.rep
, long(y
), dest
.rep
); // not incorrect
407 inline void add(const Integer
& x
, long y
, Integer
& dest
)
409 dest
.rep
= add(x
.rep
, 0, y
, dest
.rep
);
412 inline void sub(const Integer
& x
, long y
, Integer
& dest
)
414 dest
.rep
= add(x
.rep
, 0, -y
, dest
.rep
);
417 inline void mul(const Integer
& x
, long y
, Integer
& dest
)
419 dest
.rep
= multiply(x
.rep
, y
, dest
.rep
);
422 inline void div(const Integer
& x
, long y
, Integer
& dest
)
424 dest
.rep
= div(x
.rep
, y
, dest
.rep
);
427 inline void mod(const Integer
& x
, long y
, Integer
& dest
)
429 dest
.rep
= mod(x
.rep
, y
, dest
.rep
);
432 inline void and(const Integer
& x
, long y
, Integer
& dest
)
434 dest
.rep
= bitop(x
.rep
, y
, dest
.rep
, '&');
437 inline void or(const Integer
& x
, long y
, Integer
& dest
)
439 dest
.rep
= bitop(x
.rep
, y
, dest
.rep
, '|');
442 inline void xor(const Integer
& x
, long y
, Integer
& dest
)
444 dest
.rep
= bitop(x
.rep
, y
, dest
.rep
, '^');
447 inline void lshift(const Integer
& x
, long y
, Integer
& dest
)
449 dest
.rep
= lshift(x
.rep
, y
, dest
.rep
);
452 inline void rshift(const Integer
& x
, long y
, Integer
& dest
)
454 dest
.rep
= lshift(x
.rep
, -y
, dest
.rep
);
457 inline void pow(const Integer
& x
, long y
, Integer
& dest
)
459 dest
.rep
= power(x
.rep
, y
, dest
.rep
);
462 inline void abs(const Integer
& x
, Integer
& dest
)
464 dest
.rep
= abs(x
.rep
, dest
.rep
);
467 inline void negate(const Integer
& x
, Integer
& dest
)
469 dest
.rep
= negate(x
.rep
, dest
.rep
);
472 inline void complement(const Integer
& x
, Integer
& dest
)
474 dest
.rep
= compl(x
.rep
, dest
.rep
);
477 inline void add(long x
, const Integer
& y
, Integer
& dest
)
479 dest
.rep
= add(y
.rep
, 0, x
, dest
.rep
);
482 inline void sub(long x
, const Integer
& y
, Integer
& dest
)
484 dest
.rep
= add(y
.rep
, 1, x
, dest
.rep
);
487 inline void mul(long x
, const Integer
& y
, Integer
& dest
)
489 dest
.rep
= multiply(y
.rep
, x
, dest
.rep
);
492 inline void and(long x
, const Integer
& y
, Integer
& dest
)
494 dest
.rep
= bitop(y
.rep
, x
, dest
.rep
, '&');
497 inline void or(long x
, const Integer
& y
, Integer
& dest
)
499 dest
.rep
= bitop(y
.rep
, x
, dest
.rep
, '|');
502 inline void xor(long x
, const Integer
& y
, Integer
& dest
)
504 dest
.rep
= bitop(y
.rep
, x
, dest
.rep
, '^');
510 inline int operator == (const Integer
& x
, const Integer
& y
)
512 return compare(x
, y
) == 0;
515 inline int operator == (const Integer
& x
, long y
)
517 return compare(x
, y
) == 0;
520 inline int operator != (const Integer
& x
, const Integer
& y
)
522 return compare(x
, y
) != 0;
525 inline int operator != (const Integer
& x
, long y
)
527 return compare(x
, y
) != 0;
530 inline int operator < (const Integer
& x
, const Integer
& y
)
532 return compare(x
, y
) < 0;
535 inline int operator < (const Integer
& x
, long y
)
537 return compare(x
, y
) < 0;
540 inline int operator <= (const Integer
& x
, const Integer
& y
)
542 return compare(x
, y
) <= 0;
545 inline int operator <= (const Integer
& x
, long y
)
547 return compare(x
, y
) <= 0;
550 inline int operator > (const Integer
& x
, const Integer
& y
)
552 return compare(x
, y
) > 0;
555 inline int operator > (const Integer
& x
, long y
)
557 return compare(x
, y
) > 0;
560 inline int operator >= (const Integer
& x
, const Integer
& y
)
562 return compare(x
, y
) >= 0;
565 inline int operator >= (const Integer
& x
, long y
)
567 return compare(x
, y
) >= 0;
571 inline void Integer::operator += (const Integer
& y
)
573 add(*this, y
, *this);
576 inline void Integer::operator += (long y
)
578 add(*this, y
, *this);
581 inline void Integer::operator ++ ()
583 add(*this, 1, *this);
587 inline void Integer::operator -= (const Integer
& y
)
589 sub(*this, y
, *this);
592 inline void Integer::operator -= (long y
)
594 sub(*this, y
, *this);
597 inline void Integer::operator -- ()
599 add(*this, -1, *this);
604 inline void Integer::operator *= (const Integer
& y
)
606 mul(*this, y
, *this);
609 inline void Integer::operator *= (long y
)
611 mul(*this, y
, *this);
615 inline void Integer::operator &= (const Integer
& y
)
617 and(*this, y
, *this);
620 inline void Integer::operator &= (long y
)
622 and(*this, y
, *this);
625 inline void Integer::operator |= (const Integer
& y
)
630 inline void Integer::operator |= (long y
)
636 inline void Integer::operator ^= (const Integer
& y
)
638 xor(*this, y
, *this);
641 inline void Integer::operator ^= (long y
)
643 xor(*this, y
, *this);
648 inline void Integer::operator /= (const Integer
& y
)
650 div(*this, y
, *this);
653 inline void Integer::operator /= (long y
)
655 div(*this, y
, *this);
659 inline void Integer::operator %= (const Integer
& y
)
661 mod(*this, y
, *this);
664 inline void Integer::operator %= (long y
)
666 mod(*this, y
, *this);
670 inline void Integer::operator <<= (const Integer
& y
)
672 lshift(*this, y
, *this);
675 inline void Integer::operator <<= (long y
)
677 lshift(*this, y
, *this);
681 inline void Integer::operator >>= (const Integer
& y
)
683 rshift(*this, y
, *this);
686 inline void Integer::operator >>= (long y
)
688 rshift(*this, y
, *this);
692 inline Integer
operator <? (const Integer
& x
, const Integer
& y
)
694 return (compare(x
.rep
, y
.rep
) <= 0) ? x
: y
;
697 inline Integer
operator >? (const Integer
& x
, const Integer
& y
)
699 return (compare(x
.rep
, y
.rep
) >= 0)? x
: y
;
704 inline void Integer::abs()
709 inline void Integer::negate()
711 ::negate(*this, *this);
715 inline void Integer::complement()
717 ::complement(*this, *this);
721 inline int sign(const Integer
& x
)
723 return (x
.rep
->len
== 0) ? 0 : ( (x
.rep
->sgn
== 1) ? 1 : -1 );
726 inline int even(const Integer
& y
)
728 return y
.rep
->len
== 0 || !(y
.rep
->s
[0] & 1);
731 inline int odd(const Integer
& y
)
733 return y
.rep
->len
> 0 && (y
.rep
->s
[0] & 1);
736 inline char* Itoa(const Integer
& y
, int base
, int width
)
738 return Itoa(y
.rep
, base
, width
);
742 inline ostream
& operator << (ostream
& s
, const Integer
& y
)
744 return s
<< Itoa(y
.rep
);
747 inline long lg(const Integer
& x
)
752 // constructive operations
754 #if defined(__GNUG__) && !defined(NO_NRV)
756 inline Integer
operator + (const Integer
& x
, const Integer
& y
) return r
761 inline Integer
operator + (const Integer
& x
, long y
) return r
766 inline Integer
operator + (long x
, const Integer
& y
) return r
771 inline Integer
operator - (const Integer
& x
, const Integer
& y
) return r
776 inline Integer
operator - (const Integer
& x
, long y
) return r
781 inline Integer
operator - (long x
, const Integer
& y
) return r
786 inline Integer
operator * (const Integer
& x
, const Integer
& y
) return r
791 inline Integer
operator * (const Integer
& x
, long y
) return r
796 inline Integer
operator * (long x
, const Integer
& y
) return r
801 inline Integer
sqr(const Integer
& x
) return r
806 inline Integer
operator & (const Integer
& x
, const Integer
& y
) return r
811 inline Integer
operator & (const Integer
& x
, long y
) return r
816 inline Integer
operator & (long x
, const Integer
& y
) return r
821 inline Integer
operator | (const Integer
& x
, const Integer
& y
) return r
826 inline Integer
operator | (const Integer
& x
, long y
) return r
831 inline Integer
operator | (long x
, const Integer
& y
) return r
836 inline Integer
operator ^ (const Integer
& x
, const Integer
& y
) return r
841 inline Integer
operator ^ (const Integer
& x
, long y
) return r
846 inline Integer
operator ^ (long x
, const Integer
& y
) return r
851 inline Integer
operator / (const Integer
& x
, const Integer
& y
) return r
856 inline Integer
operator / (const Integer
& x
, long y
) return r
861 inline Integer
operator % (const Integer
& x
, const Integer
& y
) return r
866 inline Integer
operator % (const Integer
& x
, long y
) return r
871 inline Integer
operator << (const Integer
& x
, const Integer
& y
) return r
876 inline Integer
operator << (const Integer
& x
, long y
) return r
881 inline Integer
operator >> (const Integer
& x
, const Integer
& y
) return r
;
886 inline Integer
operator >> (const Integer
& x
, long y
) return r
891 inline Integer
pow(const Integer
& x
, long y
) return r
896 inline Integer
Ipow(long x
, long y
) return r(x
)
901 inline Integer
pow(const Integer
& x
, const Integer
& y
) return r
908 inline Integer
abs(const Integer
& x
) return r
913 inline Integer
operator - (const Integer
& x
) return r
918 inline Integer
operator ~ (const Integer
& x
) return r
923 inline Integer
atoI(const char* s
, int base
) return r
925 r
.rep
= atoIntRep(s
, base
);
928 inline Integer
gcd(const Integer
& x
, const Integer
& y
) return r
930 r
.rep
= gcd(x
.rep
, y
.rep
);
935 inline Integer
operator + (const Integer
& x
, const Integer
& y
)
937 Integer r
; add(x
, y
, r
); return r
;
940 inline Integer
operator + (const Integer
& x
, long y
)
942 Integer r
; add(x
, y
, r
); return r
;
945 inline Integer
operator + (long x
, const Integer
& y
)
947 Integer r
; add(x
, y
, r
); return r
;
950 inline Integer
operator - (const Integer
& x
, const Integer
& y
)
952 Integer r
; sub(x
, y
, r
); return r
;
955 inline Integer
operator - (const Integer
& x
, long y
)
957 Integer r
; sub(x
, y
, r
); return r
;
960 inline Integer
operator - (long x
, const Integer
& y
)
962 Integer r
; sub(x
, y
, r
); return r
;
965 inline Integer
operator * (const Integer
& x
, const Integer
& y
)
967 Integer r
; mul(x
, y
, r
); return r
;
970 inline Integer
operator * (const Integer
& x
, long y
)
972 Integer r
; mul(x
, y
, r
); return r
;
975 inline Integer
operator * (long x
, const Integer
& y
)
977 Integer r
; mul(x
, y
, r
); return r
;
980 inline Integer
sqr(const Integer
& x
)
982 Integer r
; mul(x
, x
, r
); return r
;
985 inline Integer
operator & (const Integer
& x
, const Integer
& y
)
987 Integer r
; and(x
, y
, r
); return r
;
990 inline Integer
operator & (const Integer
& x
, long y
)
992 Integer r
; and(x
, y
, r
); return r
;
995 inline Integer
operator & (long x
, const Integer
& y
)
997 Integer r
; and(x
, y
, r
); return r
;
1000 inline Integer
operator | (const Integer
& x
, const Integer
& y
)
1002 Integer r
; or(x
, y
, r
); return r
;
1005 inline Integer
operator | (const Integer
& x
, long y
)
1007 Integer r
; or(x
, y
, r
); return r
;
1010 inline Integer
operator | (long x
, const Integer
& y
)
1012 Integer r
; or(x
, y
, r
); return r
;
1015 inline Integer
operator ^ (const Integer
& x
, const Integer
& y
)
1017 Integer r
; xor(x
, y
, r
); return r
;
1020 inline Integer
operator ^ (const Integer
& x
, long y
)
1022 Integer r
; xor(x
, y
, r
); return r
;
1025 inline Integer
operator ^ (long x
, const Integer
& y
)
1027 Integer r
; xor(x
, y
, r
); return r
;
1030 inline Integer
operator / (const Integer
& x
, const Integer
& y
)
1032 Integer r
; div(x
, y
, r
); return r
;
1035 inline Integer
operator / (const Integer
& x
, long y
)
1037 Integer r
; div(x
, y
, r
); return r
;
1040 inline Integer
operator % (const Integer
& x
, const Integer
& y
)
1042 Integer r
; mod(x
, y
, r
); return r
;
1045 inline Integer
operator % (const Integer
& x
, long y
)
1047 Integer r
; mod(x
, y
, r
); return r
;
1050 inline Integer
operator << (const Integer
& x
, const Integer
& y
)
1052 Integer r
; lshift(x
, y
, r
); return r
;
1055 inline Integer
operator << (const Integer
& x
, long y
)
1057 Integer r
; lshift(x
, y
, r
); return r
;
1060 inline Integer
operator >> (const Integer
& x
, const Integer
& y
)
1062 Integer r
; rshift(x
, y
, r
); return r
;
1065 inline Integer
operator >> (const Integer
& x
, long y
)
1067 Integer r
; rshift(x
, y
, r
); return r
;
1070 inline Integer
pow(const Integer
& x
, long y
)
1072 Integer r
; pow(x
, y
, r
); return r
;
1075 inline Integer
Ipow(long x
, long y
)
1077 Integer
r(x
); pow(r
, y
, r
); return r
;
1080 inline Integer
pow(const Integer
& x
, const Integer
& y
)
1082 Integer r
; pow(x
, y
, r
); return r
;
1087 inline Integer
abs(const Integer
& x
)
1089 Integer r
; abs(x
, r
); return r
;
1092 inline Integer
operator - (const Integer
& x
)
1094 Integer r
; negate(x
, r
); return r
;
1097 inline Integer
operator ~ (const Integer
& x
)
1099 Integer r
; complement(x
, r
); return r
;
1102 inline Integer
atoI(const char* s
, int base
)
1104 Integer r
; r
.rep
= atoIntRep(s
, base
); return r
;
1107 inline Integer
gcd(const Integer
& x
, const Integer
& y
)
1109 Integer r
; r
.rep
= gcd(x
.rep
, y
.rep
); return r
;