synaps/arithm/Rg_MPZ.h

00001 #ifndef SYNAPS_ARITHM_RG_MPZ_H
00002 #define SYNAPS_ARITHM_RG_MPZ_H
00003 
00004 
00005 #include <synaps/init.h>
00006 
00007 __BEGIN_NAMESPACE_SYNAPS
00008 
00009 //----------------------------------------------------------------------
00010 std::ostream& Print(std::ostream& os, const MPZ& b)
00011  { mpz_out_str(stdout, 10, &b);  return os; }
00012 //----------------------------------------------------------------------
00013 void init(MPZ& rep) { mpz_init(&rep); }
00014 void init_set(MPZ& rep, int si)      {mpz_init_set_si(&rep, si);}
00015 void init_set(MPZ& rep, long int sl) {mpz_init_set_si(&rep, sl);}
00016 void init_set(MPZ& rep, const char*& str, unsigned int b) 
00017 {if (mpz_init_set_str(&rep, str, b))
00018         std::cerr<<"MPZ: The string "<<str<<" is not a valid number in base "<<b<<std::endl;
00019 }
00020 //----------------------------------------------------------------------
00021 void clear(MPZ& rep) { mpz_clear(&rep); }
00022 //----------------------------------------------------------------------
00023 int  cmp(const MPZ& r1, const Rg<MPZ>&  r2){ return mpz_cmp(&r1,&r2.rep()); }
00024 int  cmp(const MPZ& r1, int  r2)           { return mpz_cmp_si(&r1,(long)r2); }
00025 int  cmp(const MPZ& r1, long r2)           { return mpz_cmp_si(&r1,(long)r2); }
00026 int  cmp(const MPZ& r1, unsigned r2)       { return mpz_cmp_ui(&r1, r2); }
00027 int  cmp(const MPZ& r1, unsigned long r2)  { return mpz_cmp_ui(&r1, r2); }
00028 //----------------------------------------------------------------------  
00029 inline void assign(MPZ& p, const MPZ& q)   {  mpz_set(&p,&q); }
00030 //----------------------------------------------------------------------  
00031 inline void add(MPZ& p, const MPZ& a, const MPZ& b) {mpz_add(&p,&a,&b);}
00032 //----------------------------------------------------------------------  
00033 inline void add(MPZ& p, const MPZ& a, int b) {mpz_add_ui(&p, &a,b);}
00034 //----------------------------------------------------------------------
00035 inline void sub(MPZ& p, const MPZ& a, const MPZ& b){mpz_sub(&p,&a,&b);}
00036 //----------------------------------------------------------------------
00037 inline void mul(MPZ& p, const MPZ& a, const MPZ& b) {mpz_mul(&p,&a,&b);}
00038 inline void mul(MPZ& p, const MPZ& a, int b)        {mpz_mul_si(&p,&a,b);}
00039 //----------------------------------------------------------------------
00040 inline void div(MPZ& p, const MPZ& a, const MPZ& b) {mpz_div(&p,&a,&b);}
00041 inline void div(MPZ& p, const MPZ& a, unsigned   b) {mpz_div_ui(&p,&a,b);}
00042 //----------------------------------------------------------------------
00043 inline void mod(MPZ& p, const MPZ& a, const MPZ& b) {mpz_mod(&p,&a,&b);}
00044 inline void mod(MPZ& p, const MPZ& a, unsigned   b) {mpz_mod_ui(&p,&a,b);}
00045 //----------------------------------------------------------------------
00046 // inline void add(MPZ& p, const MPZ q)  { mpz_add(&p,&p,&q); }
00047 // inline void sub(MPZ& p, const MPZ& q) { mpz_sub(&p,&p,&q); }
00048 // inline void mul(MPZ& p, const MPZ& q) { mpz_mul(&p,&p,&q); }
00049 // inline void div(MPZ& p, const MPZ& q) { mpz_div(&p,&p,&q); }
00050 // inline void mod(MPZ& p, const MPZ& q) { mpz_mod(&p,&p,&q); }
00051 // //----------------------------------------------------------------------
00052 // inline void add(MPZ& p, int i) 
00053 //    { if(i>=0)  mpz_add_ui(&p,&p,i); else mpz_sub_ui(&p,&p,-i); }
00054 // inline void add(MPZ& p, unsigned int i) { mpz_add_ui(&p,&p,i); }
00055 // inline void sub(MPZ& p, unsigned int i) { mpz_sub_ui(&p,&p,i); }
00056 // inline void mul(MPZ& p, unsigned int i) { mpz_mul_ui(&p,&p,i); }
00057 // inline void mul(MPZ& p, int i) 
00058 // {
00059 //    if (i >= 0)
00060 //      mpz_mul_ui(&p, &p, (unsigned long) i);
00061 //    else {
00062 //      mpz_mul_ui(&p, &p, (unsigned long) (-i)); mpz_neg(&p, &p);
00063 //    }
00064 // }
00065 // inline void div(MPZ& p, unsigned int ui) { mpz_div_ui(&p, &p, ui); }
00066 // inline void div(MPZ& p, int i) 
00067 // {
00068 //   if (i >= 0)
00069 //     mpz_div_ui(&p, &p, (unsigned long) i);
00070 //   else
00071 //     {
00072 //       p._mp_size = -p._mp_size;
00073 //       mpz_div_ui(&p, &p, ((unsigned long) -i));
00074 //     }
00075 //}
00076 //----------------------------------------------------------------------
00077 
00078 __END_NAMESPACE_SYNAPS
00079 
00080 #endif // SYNAPS_ARITHM_RG_MPZ_H
00081 

SYNAPS DOCUMENTATION
logo