00001
00002
00003
00004
00005
00006
00007
00008 #ifndef _scalar_integer_hpp
00009 #define _scalar_integer_hpp
00010
00011 #include <iostream>
00012 #include <string>
00013 #include <gmp.h>
00014 #include <realroot/scalar.hpp>
00015
00016 namespace mmx {
00017
00018 typedef MP_INT MPZ;
00019
00020
00021
00022
00023
00024
00025
00026
00027 template<> inline scalar<MPZ>::~scalar ( )
00028 {
00029
00030 mpz_clear(&rep());
00031 }
00032
00033 template<> inline
00034 void scalar<MPZ>::init ( )
00035 {
00036 mpz_init(&rep());
00037 }
00038
00039 template<> inline
00040 scalar<MPZ>::scalar ()
00041 {
00042 mpz_init(&rep());
00043 }
00044
00045 template<> inline
00046 scalar<MPZ>::scalar (signed long int sl): data() {mpz_init_set_si(&rep(),sl);}
00047
00048 template<> inline
00049 scalar<MPZ>::scalar (unsigned long int ul): data() {mpz_init_set_ui(&rep(),ul);}
00050
00051 template<> inline
00052 scalar<MPZ>::scalar (int si): data() {mpz_init_set_si(&rep(), si);}
00053
00054 template<> inline
00055 scalar<MPZ>::scalar (const char *s, unsigned int base): data()
00056 {
00057 if (mpz_init_set_str(&rep(), s, base))
00058 std::cerr << "scalar<MPZ>: The string " << s
00059 << " is not a valid number in base " << base << std::endl;
00060 }
00061
00062 template<> inline
00063 scalar<MPZ>::scalar (const scalar<MPZ> & rhs)
00064 {
00065
00066
00067 mpz_init_set(&rep(), &rhs.rep());
00068 }
00069
00070
00071 template<> inline
00072 scalar<MPZ>& scalar<MPZ>::operator = (const scalar<MPZ>& rhs)
00073 {
00074
00075 if (this != &rhs) mpz_set(&rep(), &rhs.rep());
00076 return *this;
00077 }
00078 template<> inline
00079 scalar<MPZ>& scalar<MPZ>::operator = (unsigned rhs)
00080 {
00081
00082 mpz_set_ui(&rep(), rhs);
00083 return *this;
00084 }
00085
00086 template<> inline
00087 bool scalar<MPZ>::operator == (const scalar<MPZ>& rhs) const
00088 {
00089 return mpz_cmp(&rep(), &rhs.rep()) == 0;
00090 }
00091
00092 template<> inline
00093 bool scalar<MPZ>::operator == (long sl) const {
00094 return mpz_cmp_si(&rep(), sl) == 0;
00095 }
00096
00097 template<> inline
00098 bool scalar<MPZ>::operator == (int si) const {
00099 return mpz_cmp_si(&rep(), (long) si) == 0;
00100 }
00101
00102 template<> inline
00103 bool scalar<MPZ>::operator == (unsigned long ul) const
00104 {
00105 return mpz_cmp_ui(&rep(), ul) == 0;
00106 }
00107
00108
00109 template<> inline
00110 bool scalar<MPZ>::operator != (const scalar<MPZ>& rhs) const
00111 {
00112 return mpz_cmp(&rep(), &rhs.rep()) != 0;
00113 }
00114
00115 template<> inline
00116 bool scalar<MPZ>::operator != (long sl) const {
00117 return mpz_cmp_si(&rep(), sl) != 0;
00118 }
00119
00120 template<> inline
00121 bool scalar<MPZ>::operator != (int si) const {
00122 return mpz_cmp_si(&rep(), (long) si) != 0;
00123 }
00124
00125 template<> inline
00126 bool scalar<MPZ>::operator != (unsigned long ul) const
00127 {
00128 return mpz_cmp_ui(&rep(), ul) != 0;
00129 }
00130
00131 template<> inline
00132 bool scalar<MPZ>::operator > (const scalar<MPZ>& rhs) const
00133 {
00134 return mpz_cmp(&rep(), &rhs.rep()) > 0;
00135 }
00136
00137 template<> inline
00138 bool scalar<MPZ>::operator > (long sl) const {
00139 return mpz_cmp_si(&rep(), sl) > 0;
00140 }
00141
00142 template<> inline
00143 bool scalar<MPZ>::operator > (int si) const {
00144 return mpz_cmp_si(&rep(), (long) si) > 0;
00145 }
00146
00147 template<> inline
00148 bool scalar<MPZ>::operator > (unsigned long ul) const
00149 {
00150 return mpz_cmp_ui(&rep(), ul) > 0;
00151 }
00152
00153 template<> inline
00154 bool scalar<MPZ>::operator >= (const scalar<MPZ>& rhs) const
00155 {
00156 return mpz_cmp(&rep(), &rhs.rep()) >= 0;
00157 }
00158
00159 template<> inline
00160 bool scalar<MPZ>::operator >= (long sl) const {
00161 return mpz_cmp_si(&rep(), sl) >= 0;
00162 }
00163
00164 template<> inline
00165 bool scalar<MPZ>::operator >= (int si) const
00166 {
00167 return mpz_cmp_si(&rep(), (long) si) >= 0;
00168 }
00169
00170 template<> inline
00171 bool scalar<MPZ>::operator >= (unsigned long ul) const
00172 {
00173 return mpz_cmp_ui(&rep(), ul) >= 0;
00174 }
00175
00176
00177 template<> inline
00178 bool scalar<MPZ>::operator < (const scalar<MPZ>& rhs) const
00179 {
00180 return mpz_cmp(&rep(), &rhs.rep()) < 0;
00181 }
00182
00183 template<> inline
00184 bool scalar<MPZ>::operator < (long sl) const {
00185 return mpz_cmp_si(&rep(), sl) < 0;
00186 }
00187
00188 template<> inline
00189 bool scalar<MPZ>::operator < (int si) const
00190 {
00191 return mpz_cmp_si(&rep(), (long) si) < 0;
00192 }
00193
00194 template<> inline
00195 bool scalar<MPZ>::operator < (unsigned long ul) const
00196 {
00197 return mpz_cmp_ui(&rep(), ul) < 0;
00198 }
00199
00200
00201
00202 template<> inline
00203 bool scalar<MPZ>::operator <= (const scalar<MPZ>& rhs) const
00204 {
00205 return mpz_cmp(&rep(), &rhs.rep()) <= 0;
00206 }
00207
00208 template<> inline
00209 bool scalar<MPZ>::operator <= (long sl) const {
00210 return mpz_cmp_si(&rep(), sl) <= 0;
00211 }
00212
00213 template<> inline
00214 bool scalar<MPZ>::operator <= (int si) const
00215 {
00216 return mpz_cmp_si(&rep(), (long) si) <= 0;
00217 }
00218
00219 template<> inline
00220 bool scalar<MPZ>::operator <= (unsigned long ul) const
00221 {
00222 return mpz_cmp_ui(&rep(), ul) <= 0;
00223 }
00224
00225
00226 template<> inline
00227 scalar<MPZ>& scalar<MPZ>::operator = (unsigned long ul)
00228 {
00229 mpz_set_ui(&rep(), ul); return *this;
00230 }
00231
00232 template<> inline
00233 scalar<MPZ>& scalar<MPZ>::operator = (long sl)
00234 {
00235 mpz_set_si(&rep(), sl); return *this;
00236 }
00237
00238 template<> inline
00239 scalar<MPZ>& scalar<MPZ>::operator = (int ul)
00240 {
00241 mpz_init_set_si(&(this->rep()), ul); return *this;
00242 }
00243
00244 template<> inline
00245 scalar<MPZ>& scalar<MPZ>::operator += (const scalar<MPZ>& rhs)
00246 {
00247 mpz_add(&rep(), &rep(), &rhs.rep()); return *this;
00248 }
00249
00250 template<> inline
00251 scalar<MPZ>& scalar<MPZ>::operator += (unsigned long ul)
00252 {
00253 mpz_add_ui(&rep(), &rep(), ul); return *this;
00254 }
00255
00256 template<> inline
00257 scalar<MPZ>& scalar<MPZ>::operator += (long sl)
00258 {
00259 if (sl >= 0)
00260 mpz_add_ui(&rep(), &rep(), (unsigned long) sl);
00261 else
00262 mpz_sub_ui(&rep(), &rep(), ((unsigned long) -sl));
00263 return *this;
00264 }
00265
00266 template<> inline
00267 scalar<MPZ>& scalar<MPZ>::operator += (int ul)
00268 {
00269 *this += scalar<MPZ>(ul); return *this;
00270 }
00271
00272
00273 template<> inline
00274 scalar<MPZ>& scalar<MPZ>::operator -= (const scalar<MPZ>& rhs)
00275 {
00276 mpz_sub(&rep(), &rep(), &rhs.rep()); return *this;
00277 }
00278
00279 template<> inline
00280 scalar<MPZ>& scalar<MPZ>::operator -= (unsigned long ul)
00281 {
00282 mpz_sub_ui(&rep(), &rep(), ul); return *this;
00283 }
00284
00285 template<> inline
00286 scalar<MPZ>& scalar<MPZ>::operator -= (long sl)
00287 {
00288 if (sl >= 0)
00289 mpz_sub_ui(&rep(), &rep(), (unsigned long) sl);
00290 else
00291 mpz_add_ui(&rep(), &rep(), (unsigned long) sl);
00292 return *this;
00293 }
00294
00295 template<> inline
00296 scalar<MPZ>& scalar<MPZ>::operator -= (int ul)
00297 {
00298 *this -= scalar<MPZ>(ul); return *this;
00299 }
00300
00301 template<> inline
00302 scalar<MPZ>& scalar<MPZ>::operator *= (const scalar<MPZ>& rhs)
00303 {
00304 mpz_mul(&rep(), &rep(), &rhs.rep()); return *this;
00305 }
00306 template<> inline
00307 scalar<MPZ>& scalar<MPZ>::operator *= (unsigned long ul)
00308 {
00309 mpz_mul_ui(&rep(), &rep(), ul); return *this;
00310 }
00311 template<> inline
00312 scalar<MPZ>& scalar<MPZ>::operator *= (long sl)
00313 {
00314 if (sl >= 0)
00315 mpz_mul_ui(&rep(), &rep(), (unsigned long) sl);
00316 else
00317 {
00318 rep()._mp_size = -rep()._mp_size;
00319 mpz_mul_ui(&rep(), &rep(), ((unsigned long) -sl));
00320 }
00321 return *this;
00322 }
00323 template<> inline
00324 scalar<MPZ>& scalar<MPZ>::operator *= (int ul)
00325 {
00326 if (ul >= 0)
00327 mpz_mul_ui(&rep(), &rep(), (unsigned long) ul);
00328 else {
00329 mpz_mul_ui(&rep(), &rep(), (unsigned long) (-ul));
00330 mpz_neg(&rep(), &rep());
00331 }
00332 return *this;
00333 }
00334
00335 template<> inline
00336 scalar<MPZ>& scalar<MPZ>::operator /= (const scalar<MPZ>& rhs)
00337 {
00338 mpz_div(&rep(), &rep(), &rhs.rep());
00339
00340 return *this;
00341 }
00342 template<> inline
00343 scalar<MPZ>& scalar<MPZ>::operator /= (unsigned long ul)
00344 {
00345 mpz_div_ui(&rep(), &rep(), ul); return *this;
00346 }
00347
00348 template<> inline
00349 scalar<MPZ>& scalar<MPZ>::operator /= (long sl)
00350 {
00351 if (sl >= 0)
00352 mpz_div_ui(&rep(), &rep(), (unsigned long) sl);
00353 else
00354 {
00355 rep()._mp_size = -rep()._mp_size;
00356 mpz_div_ui(&rep(), &rep(), ((unsigned long) -sl));
00357 }
00358 return *this;
00359 }
00360
00361
00362 template<> inline
00363 scalar<MPZ>& scalar<MPZ>::operator %= (const scalar<MPZ>& rhs)
00364 {
00365 mpz_mod(&rep(), &rep(), &rhs.rep()); return *this;
00366 }
00367
00368 template<> inline
00369 scalar<MPZ>& scalar<MPZ>::operator %= (unsigned long ul)
00370 {
00371 mpz_mod_ui(&rep(), &rep(), ul); return *this;
00372 }
00373
00374
00375
00376
00377 inline
00378 scalar<MPZ> operator +(const scalar<MPZ>& a1, const scalar<MPZ>& a2)
00379 {
00380 scalar<MPZ> result;
00381 mpz_add(&result.rep(), &a1.rep(), &a2.rep());
00382 return result;
00383 }
00384
00385 inline
00386 scalar<MPZ> operator -(const scalar<MPZ>& a1, const scalar<MPZ>& a2)
00387 {
00388 scalar<MPZ> result;
00389 mpz_sub(&result.rep(), &a1.rep(), &a2.rep());
00390 return result;
00391 }
00392
00393 inline
00394 scalar<MPZ> operator -(const scalar<MPZ>& a1)
00395 {
00396 scalar<MPZ> r; mpz_neg(&r.rep(), &a1.rep()); return r;
00397 }
00398
00399 inline
00400 scalar<MPZ> operator *(const scalar<MPZ>& a1, const scalar<MPZ>& a2)
00401 {
00402 scalar<MPZ> result;
00403 mpz_mul(&result.rep(), &a1.rep(), &a2.rep());
00404 return result;
00405 }
00406
00407
00408 inline
00409 scalar<MPZ> operator /(const scalar<MPZ>& a1, const scalar<MPZ>& a2)
00410 {
00411 scalar<MPZ> result;
00412 mpz_div(&result.rep(), &a1.rep(), &a2.rep());
00413 return result;
00414 }
00415
00417 template<> inline
00418 void scalar<MPZ>::operator ++ ( )
00419 {
00420 mpz_add_ui(&rep(), &rep(), 1);
00421 }
00422
00424 template<> inline
00425 void scalar<MPZ>::operator -- ( )
00426 {
00427 mpz_sub_ui(&rep(), &rep(), 1);
00428 }
00429
00430 inline void convert(scalar<MPZ>& n, char *s)
00431 {
00432 mpz_init_set_str(&n.rep(), s, 10);
00433 }
00434
00435
00436
00437 inline
00438 std::ostream& operator << (std::ostream& os, const scalar<MPZ>& b)
00439 {
00440 mpz_out_str(stdout, 10, &b.rep());
00441 return os;
00442 }
00443
00444 inline char* as_charp(const scalar<MPZ>& b) {
00445 return mpz_get_str(NULL, 10, &b.rep());
00446 }
00447
00448 template<class OSTREAM> inline void
00449 print(OSTREAM& os, const scalar<MPZ>& b) {
00450 os << as_charp(b);
00451 }
00452
00453 inline
00454 std::istream& operator >> (std::istream& is, scalar<MPZ>& b)
00455 {
00456 std::string s;is >> s;
00457 mpz_init_set_str(&b.rep(),s.c_str(), 10);
00458 return is;
00459 }
00460
00461
00462
00463 template<> inline void
00464 scalar<MPZ>::Div2Exp (unsigned long exponent_of_2)
00465 {
00466 mpz_div_2exp(&rep(), &rep(), exponent_of_2);
00467 }
00468
00469 template<> inline
00470 void scalar<MPZ>::GCD (const scalar<MPZ>& b2)
00471 {
00472 mpz_gcd (&rep(), &rep(), &b2.rep());
00473 }
00474
00475
00476 template<> inline void
00477 scalar<MPZ>::Mod2Exp (unsigned long exponent_of_2)
00478 {
00479 mpz_mod_2exp(&rep(), &rep(), exponent_of_2);
00480 }
00481
00482 template<> inline void
00483 scalar<MPZ>::Mul2Exp (unsigned long exponent_of_2)
00484 {
00485 mpz_mul_2exp(&rep(), &rep(), exponent_of_2);
00486 }
00487
00488 template<> inline void
00489 scalar<MPZ>::PowMod (const scalar<MPZ>& exp, const scalar<MPZ>& m)
00490 {
00491 mpz_powm(&rep(), &rep(), &exp.rep(), &m.rep());
00492 }
00493
00494 template<> inline void
00495 scalar<MPZ>::PowMod (unsigned long exp, const scalar<MPZ>& m)
00496 {
00497 mpz_powm_ui(&rep(), &rep(), exp, &m.rep());
00498 }
00499
00500 template<> inline void
00501 scalar<MPZ>::abs ( )
00502 {
00503 if (rep()._mp_size < 0)
00504 rep()._mp_size = - rep()._mp_size;
00505 }
00506
00507 template<> inline void
00508 scalar<MPZ>::factorial (unsigned long n)
00509 {
00510 mpz_fac_ui(&rep(), n);
00511 }
00512
00513 template<> inline
00514 scalar<MPZ>& scalar<MPZ>::negate ( )
00515 {
00516 rep()._mp_size = - rep()._mp_size; return *this;
00517 }
00518
00519 inline scalar<MPZ> rfloor (const scalar<MPZ>& q) { return q; }
00520 inline scalar<MPZ> rceil (const scalar<MPZ>& q) { return rfloor(q)+1; }
00521
00522 template<> inline
00523 scalar<MPZ>& scalar<MPZ>::pow (unsigned long exp)
00524 {
00525 mpz_pow_ui(&rep(), &rep(), exp); return *this;
00526 }
00527
00528 template<> inline
00529 scalar<MPZ>& scalar<MPZ>::pow (unsigned long base, unsigned long exp)
00530 {
00531 mpz_ui_pow_ui(&rep(), base, exp); return *this;
00532 }
00533
00534 template<> inline void
00535 scalar<MPZ>::quo (const scalar<MPZ>& divisor)
00536 {
00537 mpz_mdiv (&rep(), &rep(), &divisor.rep());
00538 }
00539
00540 template<> inline void
00541 scalar<MPZ>::quo (unsigned long divisor)
00542 {
00543 mpz_mdiv_ui(&rep(), &rep(), divisor);
00544 }
00545
00546 template<> inline void
00547 scalar<MPZ>::rem (const scalar<MPZ>& divisor)
00548 {
00549 mpz_mmod(&rep(), &rep(), &divisor.rep());
00550 }
00551
00552 template<> inline unsigned long
00553 scalar<MPZ>::rem (unsigned long divisor)
00554 {
00555 return mpz_mmod_ui(&rep(), &rep(), divisor);
00556 }
00557
00558 template<> inline void
00559 scalar<MPZ>::sqrt ( )
00560 {
00561 mpz_sqrt(&rep(), &rep());
00562 }
00563
00564 inline void
00565 SqrtRem (scalar<MPZ>& sqrt, scalar<MPZ>& rem, const scalar<MPZ>& b)
00566 {
00567 mpz_sqrtrem(&sqrt.rep(), &rem.rep(), &b.rep());
00568 }
00569
00570 inline void
00571 QuoRem (scalar<MPZ>& q, scalar<MPZ>& r, const scalar<MPZ>& divdend, const scalar<MPZ>& divisor)
00572 {
00573 mpz_mdivmod(&q.rep(), &r.rep(), &divdend.rep(), &divisor.rep());
00574 }
00575
00576 inline unsigned long
00577 QuoRem (scalar<MPZ>& q, scalar<MPZ>& r, const scalar<MPZ>& divdend, unsigned long divisor)
00578 {
00579 return mpz_mdivmod_ui(&q.rep(), &r.rep(), &divdend.rep(), divisor);
00580 }
00581
00582 inline void
00583 DivMod (scalar<MPZ>& q, scalar<MPZ>& r, const scalar<MPZ>& divdend, const scalar<MPZ>& divisor)
00584 {
00585 mpz_divmod(&q.rep(), &r.rep(), &divdend.rep(), &divisor.rep());
00586 }
00587
00588 inline void
00589 DivMod (scalar<MPZ>& q, scalar<MPZ>& r, const scalar<MPZ>& divdend, unsigned long divisor)
00590 {
00591 mpz_divmod_ui(&q.rep(), &r.rep(), &divdend.rep(), divisor);
00592 }
00593
00594 inline
00595 void ExtGCD (scalar<MPZ>& gcd, scalar<MPZ>& a, scalar<MPZ>& b,
00596 const scalar<MPZ>& x, const scalar<MPZ>& y)
00597 {
00598 mpz_gcdext(&gcd.rep(), &a.rep(), &b.rep(), &x.rep(), &y.rep());
00599 }
00600
00601 inline
00602 void HalfExtGCD (scalar<MPZ>& gcd, scalar<MPZ>& a,
00603 const scalar<MPZ>& x, const scalar<MPZ>& y)
00604 {
00605 mpz_gcdext(&gcd.rep(), &a.rep(), 0, &x.rep(), &y.rep());
00606 }
00607
00608 inline unsigned long BigIntToUL (const scalar<MPZ>& b)
00609 {
00610 return mpz_get_ui(&b.rep());
00611 }
00612
00613 inline signed long BigIntToSL (const scalar<MPZ>& b)
00614 {
00615 return mpz_get_si(&b.rep());
00616 }
00617
00618 inline size_t log (const scalar<MPZ>& b)
00619 {
00620 return mpz_size(&b.rep());
00621 }
00622
00623 inline size_t log (const scalar<MPZ>& b, int base)
00624 {
00625 assert(base >= 2 && base <= 36);
00626 return mpz_sizeinbase(&b.rep(), base);
00627 }
00628
00629 inline int sign (const scalar<MPZ>& b)
00630 {
00631 if (b.rep()._mp_size == 0)
00632 return 0;
00633 else
00634 return b.rep()._mp_size > 0 ? 1 : -1;
00635 }
00636
00637 inline int compare (const scalar<MPZ>& b1, const scalar<MPZ>& b2)
00638 {
00639 return mpz_cmp(&b1.rep(), &b2.rep());
00640 }
00641
00642 inline int compare (const scalar<MPZ>& b, unsigned long ul)
00643 {
00644 return mpz_cmp_ui(&b.rep(), ul);
00645 }
00646
00647 inline int compare (const scalar<MPZ>& b, long sl)
00648 {
00649 return mpz_cmp_si(&b.rep(), sl);
00650 }
00651
00652 inline bool IsPositive (const scalar<MPZ>& b) {
00653 return b.rep()._mp_size > 0;
00654 }
00655
00656 inline bool IsNegative (const scalar<MPZ>& b) {
00657 return b.rep()._mp_size < 0;
00658 }
00659
00660 inline bool IsZero (const scalar<MPZ>& b) {
00661 return b.rep()._mp_size == 0;
00662 }
00663
00664 inline bool IsOne(const scalar<MPZ>& b) {
00665 return b.rep()._mp_size == 1 && b.rep()._mp_d[0] == 1;
00666 }
00667
00668 inline bool IsMinusOne (const scalar<MPZ>& b) {
00669 return b.rep()._mp_size == -1 && b.rep()._mp_d[0] == 1;
00670 }
00671
00672 inline bool IsOdd (const scalar<MPZ>& b) {
00673 return b.rep()._mp_size != 0 && (b.rep()._mp_d[0] & ((mp_limb_t) 1));
00674 }
00675
00676 inline bool IsEven (const scalar<MPZ>& b) {
00677 return b.rep()._mp_size == 0 || (b.rep()._mp_d[0] ^ ((mp_limb_t) 0));
00678 }
00679
00680 inline bool IsPerfectSquare (const scalar<MPZ>& b)
00681 {
00682 return mpz_perfect_square_p(&b.rep());
00683 }
00684
00685 inline bool IsProbablyPrime (const scalar<MPZ>& b, int reps )
00686 {
00687 return mpz_probab_prime_p(&b.rep(), reps);
00688 }
00689
00690 inline
00691 scalar<MPZ> operator << (const scalar<MPZ>& x, long int s) {
00692 scalar<MPZ> r;
00693 if (s >= 0) mpz_mul_2exp (&r.rep(), &x.rep(), s);
00694 else mpz_div_2exp (&r.rep(), &x.rep(), -s);
00695 return r;
00696 }
00697
00698 inline
00699 scalar<MPZ>& operator <<= (scalar<MPZ>& x, long int s)
00700 {
00701 if (s >= 0) mpz_mul_2exp (&x.rep(), &x.rep(), s);
00702 else mpz_div_2exp (&x.rep(), &x.rep(), -s);
00703 return x;
00704 }
00705
00706 inline scalar<MPZ> Size( const scalar<MPZ> & z ) { return abs(z); };
00707
00708 inline long int bit_size(const scalar<MPZ>& z) {return mpz_sizeinbase(&z.rep(),2);}
00709
00710 inline scalar<MPZ> gcd(const scalar<MPZ> & a, const scalar<MPZ> & b)
00711 {
00712 scalar<MPZ> r;
00713 mpz_gcd(&r.rep(), &a.rep(), &b.rep());
00714 return r;
00715 }
00716
00717 inline scalar<MPZ> lcm(const scalar<MPZ> & a, const scalar<MPZ> & b) { return (a*b)/gcd(a,b); }
00718
00719 inline scalar<MPZ> pow(const scalar<MPZ>& a, unsigned n)
00720 {
00721 scalar<MPZ> r;
00722 mpz_pow_ui(&r.rep(), &a.rep(), n);
00723 return r;
00724 }
00725
00726 inline scalar<MPZ> isqrt(const scalar<MPZ>& a) { return sqrt(a) + 1; }
00727
00728
00729 namespace let
00730 {
00731 inline void assign(scalar<MPZ>& z, char * s) { mpz_set_str(&z.rep(), s, 10); }
00732 inline void assign(scalar<MPZ>& z, int n) { mpz_set_si(&z.rep(),n); }
00733 inline void assign(scalar<MPZ>& z, double d ) { z = (int)d; };
00734 inline void assign(scalar<MPZ>& x, const scalar<MPZ>& r) { mpz_set(&x.rep(),&r.rep()); }
00735 inline void assign(int& x, const scalar<MPZ>& r) { x = mpz_get_si(&r.rep()); }
00736 inline void assign(long int& x, const scalar<MPZ>& r) { x = mpz_get_si(&r.rep()); }
00737 inline void assign( double & r, const scalar<MPZ> & z ) { r = mpz_get_d(&z.rep()); }
00738
00739 }
00740
00741
00742 inline double to_double(const scalar<MPZ>& z) { return mpz_get_d(&z.rep()); }
00743 inline double as_double(const scalar<MPZ>& z) { return mpz_get_d(&z.rep()); }
00744
00745 template<typename T,typename F> struct as_helper;
00746 template<> struct as_helper<double,scalar<MPZ> > {
00747 static inline double cv(const scalar<MPZ>& x) {return mpz_get_d(&x.rep());}
00748 };
00749 }
00750
00751 #endif // //SCL_MPZ_H