Changeset a52291 in git


Ignore:
Timestamp:
Nov 24, 2011, 2:35:53 PM (11 years ago)
Author:
Martin Lee <martinlee84@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a800fe4b3e9d37a38c5a10cc0ae9dfa0c15a4ee6')
Children:
8b46459e9dad8bec212484f1bfce347c45e41371
Parents:
1c48503bfae9bb885752ba741bd0a236df633d13
git-author:
Martin Lee <martinlee84@web.de>2011-11-24 14:35:53+01:00
git-committer:
Oleksandr Motsak <motsak@mathematik.uni-kl.de>2011-11-24 21:10:03+01:00
Message:
replacing MP_INT by mpz_t

Conflicts:

	factory/cf_factory.h
Location:
factory
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • factory/NTLconvert.cc

    r1c48503 ra52291  
    653653    char* stringtemp;
    654654
    655     gmp_val[0]=getmpi(f.getval());
     655    gmp_val[0]=*getmpi(f.getval());
    656656    int l=mpz_sizeinbase(gmp_val,10)+2;
    657657    stringtemp=(char*)Alloc(l);
  • factory/cf_factory.cc

    r1c48503 ra52291  
    221221
    222222InternalCF *
    223 CFFactory::basic ( const MP_INT & num )
     223CFFactory::basic ( const mpz_ptr num )
    224224{
    225225    if ( currenttype != IntegerDomain ) {
     
    239239
    240240InternalCF *
    241 CFFactory::rational ( const MP_INT & num, const MP_INT & den, bool normalize )
     241CFFactory::rational ( const mpz_ptr num, const mpz_ptr den, bool normalize )
    242242{
    243243    if ( normalize ) {
     
    267267}
    268268
    269 MP_INT getmpi ( InternalCF * value, bool symmetric )
     269mpz_ptr getmpi ( InternalCF * value, bool symmetric )
    270270{
    271271    ASSERT( ! is_imm( value ) && ( value->levelcoeff() == PrimePowerDomain || value->levelcoeff() == IntegerDomain ), "illegal operation" );
    272     MP_INT dummy;
     272    mpz_ptr dummy= new mpz_t;
    273273    if ( value->levelcoeff() == IntegerDomain )
    274         mpz_init_set( &dummy, &InternalInteger::MPI( value ) );
     274        mpz_init_set( dummy, InternalInteger::MPI( value ) );
    275275    else  if ( symmetric ) {
    276         mpz_init( &dummy );
    277         if ( mpz_cmp( &InternalPrimePower::primepowhalf, &InternalPrimePower::MPI( value ) ) < 0 )
    278             mpz_sub( &dummy, &InternalPrimePower::MPI( value ), &InternalPrimePower::primepow );
    279         else
    280             mpz_set( &dummy, &InternalPrimePower::MPI( value ) );
    281     }
    282     else
    283         mpz_init_set( &dummy, &InternalPrimePower::MPI( value ) );
     276        mpz_init( dummy );
     277        if ( mpz_cmp( InternalPrimePower::primepowhalf, InternalPrimePower::MPI( value ) ) < 0 )
     278            mpz_sub( dummy, InternalPrimePower::MPI( value ), InternalPrimePower::primepow );
     279        else
     280            mpz_set( dummy, InternalPrimePower::MPI( value ) );
     281    }
     282    else
     283        mpz_init_set( dummy, InternalPrimePower::MPI( value ) );
    284284    return dummy;
    285285}
  • factory/cf_factory.h

    r1c48503 ra52291  
    2828    static InternalCF * basic ( int type, const char * const str );
    2929    static InternalCF * basic ( int type, int value, bool nonimm );
    30     static InternalCF * basic ( const MP_INT & num );
     30    static InternalCF * basic ( const mpz_ptr num );
    3131    static InternalCF * rational ( int num, int den );
    32     static InternalCF * rational ( const MP_INT & num, const MP_INT & den, bool normalize );
     32    static InternalCF * rational ( const mpz_ptr num, const mpz_ptr den, bool normalize );
    3333    static InternalCF * poly ( const Variable & v, int exp, const CanonicalForm & c );
    3434    static InternalCF * poly ( const Variable & v, int exp = 1 );
    3535};
    3636
    37 
    38 MP_INT getmpi ( InternalCF * value, bool symmetric = true );
     37mpz_ptr getmpi ( InternalCF * value, bool symmetric = true );
    3938
    4039#endif /* ! INCL_CF_FACTORY_H */
  • factory/fac_cantzass.cc

    r1c48503 ra52291  
    1919static CFFList CantorZassenhausFactorFFGF( const CanonicalForm & f, int d, int q, const CFRandom & );
    2020
    21 static CFFList CantorZassenhausFactorExt( const CanonicalForm & g, int s, MP_INT * q, const CFRandom & gen );
     21static CFFList CantorZassenhausFactorExt( const CanonicalForm & g, int s, mpz_t q, const CFRandom & gen );
    2222
    2323static CFFList distinctDegreeFactorFFGF ( const CanonicalForm & f, int q );
     
    3737static CanonicalForm powerMod2( const CanonicalForm & f, int p, int s, const CanonicalForm & d );
    3838
    39 static CanonicalForm powerMod2( const CanonicalForm & f, MP_INT * q, int s, const CanonicalForm & d );
     39static CanonicalForm powerMod2( const CanonicalForm & f, mpz_t q, int s, const CanonicalForm & d );
    4040
    4141CFFList FpFactorizeUnivariateCZ( const CanonicalForm& f, bool issqrfree, int numext, const Variable alpha, const Variable beta )
     
    4646    int d, q, n = 0;
    4747    bool galoisfield = getGFDegree() > 1;
    48     MP_INT qq;
     48    mpz_t qq;
    4949
    5050    if ( galoisfield )
     
    5757        else
    5858            n = getMipo( alpha ).degree() * getMipo( beta ).degree();
    59         mpz_init( &qq );
    60         mpz_ui_pow_ui ( &qq, q, n );
     59        mpz_init( qq );
     60        mpz_ui_pow_ui ( qq, q, n );
    6161    }
    6262    if ( LC( f ).isOne() )
     
    8282             if ( numext == 1 ) {
    8383                   AlgExtRandomF tmpalpha( alpha );
    84                     HH = CantorZassenhausFactorExt( j.getItem().factor(), j.getItem().exp(), &qq, tmpalpha );
     84                    HH = CantorZassenhausFactorExt( j.getItem().factor(), j.getItem().exp(), qq, tmpalpha );
    8585             }
    8686             else {
    8787                   AlgExtRandomF tmpalphabeta( alpha, beta );
    88                     HH = CantorZassenhausFactorExt( j.getItem().factor(), j.getItem().exp(), &qq, tmpalphabeta );
     88                    HH = CantorZassenhausFactorExt( j.getItem().factor(), j.getItem().exp(), qq, tmpalphabeta );
    8989             }
    9090            }
     
    100100    }
    101101    if ( numext > 0 )
    102         mpz_clear( &qq );
     102        mpz_clear( qq );
    103103    return H;
    104104}
     
    171171}
    172172
    173 CFFList CantorZassenhausFactorExt( const CanonicalForm & g, int s, MP_INT * q, const CFRandom & gen )
     173CFFList CantorZassenhausFactorExt( const CanonicalForm & g, int s, mpz_t q, const CFRandom & gen )
    174174{
    175175    CanonicalForm f = g;
     
    228228    int odd;
    229229
    230     MP_INT m;
    231 
    232     mpz_init( &m );
    233     mpz_ui_pow_ui ( &m, p, s );
    234     while ( mpz_cmp_si( &m, 0 ) != 0 )
     230    mpz_t m;
     231
     232    mpz_init( m );
     233    mpz_ui_pow_ui ( m, p, s );
     234    while ( mpz_cmp_si( m, 0 ) != 0 )
    235235    {
    236         odd = mpz_fdiv_q_ui( &m, &m, 2 );
     236        odd = mpz_fdiv_q_ui( m, m, 2 );
    237237        if ( odd != 0 )
    238238            prod = (prod * b) % d;
    239         if ( mpz_cmp_si( &m, 0 ) != 0 )
     239        if ( mpz_cmp_si( m, 0 ) != 0 )
    240240            b = (b*b) % d;
    241241    }
    242     mpz_clear( &m );
     242    mpz_clear( m );
    243243    return prod;
    244244}
     
    250250    int odd;
    251251
    252     MP_INT m;
    253 
    254     mpz_init( &m );
    255     mpz_ui_pow_ui ( &m, p, s );
    256     mpz_sub_ui( &m, &m, 1 );
    257     mpz_fdiv_q_ui( &m, &m, 2 );
    258     while ( mpz_cmp_si( &m, 0 ) != 0 )
     252    mpz_t m;
     253
     254    mpz_init( m );
     255    mpz_ui_pow_ui ( m, p, s );
     256    mpz_sub_ui( m, m, 1 );
     257    mpz_fdiv_q_ui( m, m, 2 );
     258    while ( mpz_cmp_si( m, 0 ) != 0 )
    259259    {
    260         odd = mpz_fdiv_q_ui( &m, &m, 2 );
     260        odd = mpz_fdiv_q_ui( m, m, 2 );
    261261        if ( odd != 0 )
    262262            prod = (prod * b) % d;
    263         if ( mpz_cmp_si( &m, 0 ) != 0 )
     263        if ( mpz_cmp_si( m, 0 ) != 0 )
    264264            b = (b*b) % d;
    265265    }
    266     mpz_clear( &m );
    267     return prod;
    268 }
    269 
    270 CanonicalForm powerMod2( const CanonicalForm & f, MP_INT * q, int s, const CanonicalForm & d )
     266    mpz_clear( m );
     267    return prod;
     268}
     269
     270CanonicalForm powerMod2( const CanonicalForm & f, mpz_t q, int s, const CanonicalForm & d )
    271271{
    272272    CanonicalForm prod = 1;
     
    274274    int odd;
    275275
    276     MP_INT m;
    277 
    278     mpz_init( &m );
    279     mpz_pow_ui( &m, q, s );
    280     mpz_sub_ui( &m, &m, 1 );
    281     mpz_fdiv_q_ui( &m, &m, 2 );
    282     while ( mpz_cmp_si( &m, 0 ) != 0 )
     276    mpz_t m;
     277
     278    mpz_init( m );
     279    mpz_pow_ui( m, q, s );
     280    mpz_sub_ui( m, m, 1 );
     281    mpz_fdiv_q_ui( m, m, 2 );
     282    while ( mpz_cmp_si( m, 0 ) != 0 )
    283283    {
    284         odd = mpz_fdiv_q_ui( &m, &m, 2 );
     284        odd = mpz_fdiv_q_ui( m, m, 2 );
    285285        if ( odd != 0 )
    286286            prod = (prod * b) % d;
    287         if ( mpz_cmp_si( &m, 0 ) != 0 )
     287        if ( mpz_cmp_si( m, 0 ) != 0 )
    288288            b = (b*b) % d;
    289289    }
    290     mpz_clear( &m );
    291     return prod;
    292 }
     290    mpz_clear( m );
     291    return prod;
     292}
  • factory/gmpext.h

    r1c48503 ra52291  
    1313
    1414inline bool
    15 mpz_is_imm( const MP_INT * mpi )
     15mpz_is_imm( const mpz_t mpi )
    1616{
    1717    return ( mpz_cmp_si( mpi, MINIMMEDIATE ) >= 0 ) &&
  • factory/int_int.cc

    r1c48503 ra52291  
    1717InternalInteger::InternalInteger()
    1818{
    19     mpz_init( &thempi );
     19    mpz_init( thempi );
    2020}
    2121
    2222InternalInteger::InternalInteger( const int i )
    2323{
    24     mpz_init_set_si( &thempi, i );
    25 }
    26 
    27 InternalInteger::InternalInteger( const MP_INT & mpi) : thempi( mpi ) {}
     24    mpz_init_set_si( thempi, i );
     25}
     26
     27InternalInteger::InternalInteger( const mpz_ptr mpi) { thempi[0]=*mpi;}
    2828
    2929InternalInteger::InternalInteger( const char * str, const int base )
    3030{
    31     mpz_init_set_str( &thempi, str, base );
     31    mpz_init_set_str( thempi, str, base );
    3232}
    3333
    3434InternalInteger::~InternalInteger()
    3535{
    36     mpz_clear( &thempi );
     36    mpz_clear( thempi );
    3737}
    3838
     
    4040{
    4141    mpz_t dummy;
    42     mpz_init_set( dummy, &thempi );
    43     return new InternalInteger( dummy[0] );
     42    mpz_init_set( dummy, thempi );
     43    return new InternalInteger( dummy );
    4444}
    4545
     
    4747void InternalInteger::print( OSTREAM & os, char * c )
    4848{
    49     if ( *c == '*' && mpz_cmp_si( &thempi, 1 ) == 0 )
     49    if ( *c == '*' && mpz_cmp_si( thempi, 1 ) == 0 )
    5050        os << c+1;
    51     else if ( *c == '*' && mpz_cmp_si( &thempi, -1 ) == 0 )
     51    else if ( *c == '*' && mpz_cmp_si( thempi, -1 ) == 0 )
    5252        os << '-' << c+1;
    5353    else {
    54         char * str = new char[mpz_sizeinbase( &thempi, 10 ) + 2];
    55         str = mpz_get_str( str, 10, &thempi );
     54        char * str = new char[mpz_sizeinbase( thempi, 10 ) + 2];
     55        str = mpz_get_str( str, 10, thempi );
    5656        os << str << c;
    5757        delete [] str;
     
    6262bool InternalInteger::is_imm() const
    6363{
    64     return mpz_is_imm( &thempi );
     64    return mpz_is_imm( thempi );
    6565}
    6666
     
    9090        decRefCount();
    9191        mpz_t dummy;
    92         mpz_init_set( dummy, &thempi );
     92        mpz_init_set( dummy, thempi );
    9393        mpz_neg( dummy, dummy );
    94         return new InternalInteger( dummy[0] );
    95     }
    96     else
    97     {
    98         mpz_neg( &thempi, &thempi );
     94        return new InternalInteger( dummy );
     95    }
     96    else
     97    {
     98        mpz_neg( thempi, thempi );
    9999        return this;
    100100    }
     
    110110        mpz_t dummy;
    111111        mpz_init( dummy );
    112         mpz_add( dummy, &thempi, &MPI( c ) );
     112        mpz_add( dummy, thempi, MPI( c ) );
    113113        if ( mpz_is_imm( dummy ) )
    114114        {
     
    118118        }
    119119        else
    120             return new InternalInteger( dummy[0] );
    121     }
    122     else
    123     {
    124         mpz_add( &thempi, &thempi, &MPI( c ) );
    125         if ( mpz_is_imm( &thempi ) )
    126         {
    127             InternalCF * res = int2imm( mpz_get_si( &thempi ) );
     120            return new InternalInteger( dummy );
     121    }
     122    else
     123    {
     124        mpz_add( thempi, thempi, MPI( c ) );
     125        if ( mpz_is_imm( thempi ) )
     126        {
     127            InternalCF * res = int2imm( mpz_get_si( thempi ) );
    128128            delete this;
    129129            return res;
     
    141141        mpz_t dummy;
    142142        mpz_init( dummy );
    143         mpz_sub( dummy, &thempi, &MPI( c ) );
     143        mpz_sub( dummy, thempi, MPI( c ) );
    144144        if ( mpz_is_imm( dummy ) )
    145145        {
     
    149149        }
    150150        else
    151             return new InternalInteger( dummy[0] );
    152     }
    153     else
    154     {
    155         mpz_sub( &thempi, &thempi, &MPI( c ) );
    156         if ( mpz_is_imm( &thempi ) )
    157         {
    158             InternalCF * res = int2imm( mpz_get_si( &thempi ) );
     151            return new InternalInteger( dummy );
     152    }
     153    else
     154    {
     155        mpz_sub( thempi, thempi, MPI( c ) );
     156        if ( mpz_is_imm( thempi ) )
     157        {
     158            InternalCF * res = int2imm( mpz_get_si( thempi ) );
    159159            delete this;
    160160            return res;
     
    172172        mpz_t dummy;
    173173        mpz_init( dummy );
    174         mpz_mul( dummy, &thempi, &MPI( c ) );
     174        mpz_mul( dummy, thempi, MPI( c ) );
    175175        #if 0
    176176        if ( mpz_is_imm( dummy ) )
     
    183183        else
    184184        #endif
    185             return new InternalInteger( dummy[0] );
    186     }
    187     else
    188     {
    189         mpz_mul( &thempi, &thempi, &MPI( c ) );
     185            return new InternalInteger( dummy );
     186    }
     187    else
     188    {
     189        mpz_mul( thempi, thempi, MPI( c ) );
    190190        #if 0
    191191        if ( mpz_is_imm( &thempi ) )
     
    208208{
    209209    ASSERT( ! ::is_imm( c ) && c->levelcoeff() == IntegerDomain, "incompatible base coefficients" );
    210     return mpz_cmp( &thempi, &MPI( c ) );
     210    return mpz_cmp( thempi, MPI( c ) );
    211211}
    212212
     
    215215{
    216216    ASSERT( ::is_imm( c ) == INTMARK, "incompatible base coefficients" );
    217     return mpz_cmp_si( &thempi, imm2int( c ) );
     217    return mpz_cmp_si( thempi, imm2int( c ) );
    218218}
    219219//}}}
     
    229229        mpz_init( dummy );
    230230        if ( cc < 0 )
    231             mpz_sub_ui( dummy, &thempi, -cc );
    232         else
    233             mpz_add_ui( dummy, &thempi, cc );
     231            mpz_sub_ui( dummy, thempi, -cc );
     232        else
     233            mpz_add_ui( dummy, thempi, cc );
    234234        if ( mpz_is_imm( dummy ) )
    235235        {
     
    239239        }
    240240        else
    241             return new InternalInteger( dummy[0] );
     241            return new InternalInteger( dummy );
    242242    }
    243243    else
    244244    {
    245245        if ( cc < 0 )
    246             mpz_sub_ui( &thempi, &thempi, -cc );
    247         else
    248             mpz_add_ui( &thempi, &thempi, cc );
    249         if ( mpz_is_imm( &thempi ) )
    250         {
    251             InternalCF * res = int2imm( mpz_get_si( &thempi ) );
     246            mpz_sub_ui( thempi, thempi, -cc );
     247        else
     248            mpz_add_ui( thempi, thempi, cc );
     249        if ( mpz_is_imm( thempi ) )
     250        {
     251            InternalCF * res = int2imm( mpz_get_si( thempi ) );
    252252            delete this;
    253253            return res;
     
    269269        {
    270270            mpz_init_set_si( dummy, cc );
    271             mpz_sub( dummy, dummy, &thempi );
     271            mpz_sub( dummy, dummy, thempi );
    272272        }
    273273        else
     
    275275            mpz_init( dummy );
    276276            if ( cc < 0 )
    277                 mpz_add_ui( dummy, &thempi, -cc );
     277                mpz_add_ui( dummy, thempi, -cc );
    278278            else
    279                 mpz_sub_ui( dummy, &thempi, cc );
     279                mpz_sub_ui( dummy, thempi, cc );
    280280        }
    281281        if ( mpz_is_imm( dummy ) )
     
    286286        }
    287287        else
    288             return new InternalInteger( dummy[0] );
     288            return new InternalInteger( dummy );
    289289    }
    290290    else
     
    294294            mpz_t dummy;
    295295            mpz_init_set_si( dummy, cc );
    296             mpz_sub( &thempi, dummy, &thempi );
     296            mpz_sub( thempi, dummy, thempi );
    297297            mpz_clear( dummy );
    298298        }
    299299        else
    300300            if ( cc < 0 )
    301                 mpz_add_ui( &thempi, &thempi, -cc );
     301                mpz_add_ui( thempi, thempi, -cc );
    302302            else
    303                 mpz_sub_ui( &thempi, &thempi, cc );
    304         if ( mpz_is_imm( &thempi ) )
    305         {
    306             InternalCF * res = int2imm( mpz_get_si( &thempi ) );
     303                mpz_sub_ui( thempi, thempi, cc );
     304        if ( mpz_is_imm( thempi ) )
     305        {
     306            InternalCF * res = int2imm( mpz_get_si( thempi ) );
    307307            delete this;
    308308            return res;
     
    324324        if ( cc < 0 )
    325325        {
    326             mpz_mul_ui( dummy, &thempi, -cc );
     326            mpz_mul_ui( dummy, thempi, -cc );
    327327            mpz_neg( dummy, dummy );
    328328        }
    329329        else
    330             mpz_mul_ui( dummy, &thempi, cc );
     330            mpz_mul_ui( dummy, thempi, cc );
    331331        if ( mpz_is_imm( dummy ) )
    332332        {
     
    336336        }
    337337        else
    338             return new InternalInteger( dummy[0] );
     338            return new InternalInteger( dummy );
    339339    }
    340340    else
     
    342342        if ( cc < 0 )
    343343        {
    344             mpz_mul_ui( &thempi, &thempi, -cc );
    345             mpz_neg( &thempi, &thempi );
    346         }
    347         else
    348             mpz_mul_ui( &thempi, &thempi, cc );
    349         if ( mpz_is_imm( &thempi ) )
    350         {
    351             InternalCF * res = int2imm( mpz_get_si( &thempi ) );
     344            mpz_mul_ui( thempi, thempi, -cc );
     345            mpz_neg( thempi, thempi );
     346        }
     347        else
     348            mpz_mul_ui( thempi, thempi, cc );
     349        if ( mpz_is_imm( thempi ) )
     350        {
     351            InternalCF * res = int2imm( mpz_get_si( thempi ) );
    352352            delete this;
    353353            return res;
     
    372372    mpz_t result;
    373373    mpz_init( result );
    374     mpz_gcd( result, &thempi, &MPI( c ) );
     374    mpz_gcd( result, thempi, MPI( c ) );
    375375    mpz_abs( result, result );
    376376
     
    383383    }
    384384    else
    385         return new InternalInteger( result[0] );
     385        return new InternalInteger( result );
    386386}
    387387
     
    409409    mpz_init( dummy );
    410410    // we do not need dummy since we know that cInt != 0
    411     cInt = mpz_gcd_ui( dummy, &thempi, cInt );
     411    cInt = mpz_gcd_ui( dummy, thempi, cInt );
    412412    mpz_clear( dummy );
    413413    if ( cInt < 0 ) cInt = -cInt;
     
    434434    mpz_init( aMPI );
    435435    mpz_init( bMPI );
    436     mpz_gcdext( result, aMPI, bMPI, &thempi, &MPI( c ) );
     436    mpz_gcdext( result, aMPI, bMPI, thempi, MPI( c ) );
    437437
    438438    // check and modify signs
     
    451451    }
    452452    else
    453         a = CanonicalForm( new InternalInteger( aMPI[0] ) );
     453        a = CanonicalForm( new InternalInteger( aMPI ) );
    454454    if ( mpz_is_imm( bMPI ) )
    455455    {
     
    458458    }
    459459    else
    460         b = CanonicalForm( new InternalInteger( bMPI[0] ) );
     460        b = CanonicalForm( new InternalInteger( bMPI ) );
    461461    if ( mpz_is_imm( result ) )
    462462    {
     
    466466    }
    467467    else
    468         return new InternalInteger( result[0] );
     468        return new InternalInteger( result );
    469469}
    470470
     
    515515int InternalInteger::intval() const
    516516{
    517   return (int)mpz_get_si( &thempi );
     517  return (int)mpz_get_si( thempi );
    518518}
    519519
    520520int InternalInteger::intmod( int p ) const
    521521{
    522   return (int)mpz_fdiv_ui( &thempi, (unsigned long)p );
     522  return (int)mpz_fdiv_ui( thempi, (unsigned long)p );
    523523}
    524524
     
    528528InternalInteger::sign () const
    529529{
    530     return mpz_sgn( &thempi );
     530    return mpz_sgn( thempi );
    531531}
    532532//}}}
     
    537537InternalInteger::sqrt ()
    538538{
    539     ASSERT( mpz_cmp_si( &thempi, 0 ) >= 0, "sqrt() argument < 0" );
     539    ASSERT( mpz_cmp_si( thempi, 0 ) >= 0, "sqrt() argument < 0" );
    540540    mpz_t result;
    541541    mpz_init( result );
    542     mpz_sqrt( result, &thempi );
     542    mpz_sqrt( result, thempi );
    543543    if ( mpz_is_imm( result ) )
    544544    {
     
    548548    }
    549549    else
    550         return new InternalInteger( result[0] );
     550        return new InternalInteger( result );
    551551}
    552552//}}}
     
    557557InternalInteger::ilog2 ()
    558558{
    559     ASSERT( mpz_cmp_si( &thempi, 0 ) > 0, "log() argument <= 0" );
    560     return mpz_sizeinbase( &thempi, 2 ) - 1;
    561 }
    562 //}}}
     559    ASSERT( mpz_cmp_si( thempi, 0 ) > 0, "log() argument <= 0" );
     560    return mpz_sizeinbase( thempi, 2 ) - 1;
     561}
     562//}}}
  • factory/int_int.h

    r1c48503 ra52291  
    3131{
    3232private:
    33     MP_INT thempi;
     33    mpz_t thempi;
    3434
    3535    // auxilliary methods
     
    3737    inline InternalCF * uiNormalizeMyself ();
    3838
    39     static inline InternalCF * normalizeMPI ( MP_INT & );
    40     static inline InternalCF * uiNormalizeMPI ( MP_INT & );
    41 
    42     static inline MP_INT & MPI ( const InternalCF * const c );
     39    static inline InternalCF * normalizeMPI ( mpz_ptr );
     40    static inline InternalCF * uiNormalizeMPI ( mpz_ptr );
     41
     42    static inline mpz_ptr MPI ( const InternalCF * const c );
    4343#ifdef HAVE_OMALLOC
    4444  static const omBin InternalInteger_bin;
     
    6565    InternalInteger( const int i );
    6666    InternalInteger( const char * str, const int base=10 );
    67     InternalInteger( const MP_INT & );
     67    InternalInteger( const mpz_ptr );
    6868    ~InternalInteger();
    6969    InternalCF* deepCopyObject() const;
     
    123123    friend void gmp_numerator ( const CanonicalForm & f, mpz_ptr result);
    124124    friend void gmp_denominator ( const CanonicalForm & f, mpz_ptr result );
    125     friend MP_INT getmpi ( InternalCF * value, bool symmetric );
     125    friend mpz_ptr getmpi ( InternalCF * value, bool symmetric );
    126126};
    127127
     
    148148    ASSERT( getRefCount() == 1, "internal error: must not delete CO" );
    149149
    150     if ( mpz_is_imm( &thempi ) ) {
    151         InternalCF * result = int2imm( mpz_get_si( &thempi ) );
     150    if ( mpz_is_imm( thempi ) ) {
     151        InternalCF * result = int2imm( mpz_get_si( thempi ) );
    152152        delete this;
    153153        return result;
     
    161161    ASSERT( getRefCount() == 1, "internal error: must not delete CO" );
    162162
    163     if ( mpz_is_imm( &thempi ) ) {
    164         InternalCF * result = int2imm( mpz_get_ui( &thempi ) );
     163    if ( mpz_is_imm( thempi ) ) {
     164        InternalCF * result = int2imm( mpz_get_ui( thempi ) );
    165165        delete this;
    166166        return result;
     
    170170//}}}
    171171
    172 //{{{ static inline InternalCF * InternalInteger::normalizeMPI, uiNormalizeMPI ( MP_INT & aMpi )
     172//{{{ static inline InternalCF * InternalInteger::normalizeMPI, uiNormalizeMPI ( mpz_ptr aMpi )
    173173//{{{ docu
    174174//
     
    186186//}}}
    187187inline InternalCF *
    188 InternalInteger::normalizeMPI ( MP_INT & aMpi )
    189 {
    190     if ( mpz_is_imm( &aMpi ) ) {
    191         InternalCF * result = int2imm( mpz_get_si( &aMpi ) );
    192         mpz_clear( &aMpi );
     188InternalInteger::normalizeMPI ( mpz_ptr aMpi )
     189{
     190    if ( mpz_is_imm( aMpi ) ) {
     191        InternalCF * result = int2imm( mpz_get_si( aMpi ) );
     192        mpz_clear( aMpi );
    193193        return result;
    194194    } else
     
    197197
    198198inline InternalCF *
    199 InternalInteger::uiNormalizeMPI ( MP_INT & aMpi )
    200 {
    201     if ( mpz_is_imm( &aMpi ) ) {
    202         InternalCF * result = int2imm( mpz_get_ui( &aMpi ) );
    203         mpz_clear( &aMpi );
     199InternalInteger::uiNormalizeMPI ( mpz_ptr aMpi )
     200{
     201    if ( mpz_is_imm( aMpi ) ) {
     202        InternalCF * result = int2imm( mpz_get_ui( aMpi ) );
     203        mpz_clear( aMpi );
    204204        return result;
    205205    } else
     
    208208//}}}
    209209
    210 //{{{ inline MP_INT & InternalInteger::MPI ( const InternalCF * const c )
     210//{{{ inline mpz_ptr InternalInteger::MPI ( const InternalCF * const c )
    211211//{{{ docu
    212212//
     
    217217//
    218218//}}}
    219 inline MP_INT &
     219inline mpz_ptr
    220220InternalInteger::MPI ( const InternalCF * const c )
    221221{
  • factory/int_intdiv.cc

    r1c48503 ra52291  
    3333
    3434    if ( cf_glob_switches.isOn( SW_RATIONAL ) ) {
    35         MP_INT n, d;
    36         mpz_init_set( &n, &thempi );
    37         mpz_init_set( &d, &MPI( c ) );
     35        mpz_t n, d;
     36        mpz_init_set( n, thempi );
     37        mpz_init_set( d, MPI( c ) );
    3838        if ( deleteObject() ) delete this;
    3939        InternalRational * result = new InternalRational( n, d );
     
    4343    if ( getRefCount() > 1 ) {
    4444        decRefCount();
    45         MP_INT mpiResult;
    46         mpz_init( &mpiResult );
    47         if ( mpz_sgn( &MPI( c ) ) > 0 )
    48             mpz_fdiv_q( &mpiResult, &thempi, &MPI( c ) );
     45        mpz_t mpiResult;
     46        mpz_init( mpiResult );
     47        if ( mpz_sgn( MPI( c ) ) > 0 )
     48            mpz_fdiv_q( mpiResult, thempi, MPI( c ) );
    4949        else
    50             mpz_cdiv_q( &mpiResult, &thempi, &MPI( c ) );
     50            mpz_cdiv_q( mpiResult, thempi, MPI( c ) );
    5151        return normalizeMPI( mpiResult );
    5252    } else {
    53         if ( mpz_sgn( &MPI( c ) ) > 0 )
    54             mpz_fdiv_q( &thempi, &thempi, &MPI( c ) );
     53        if ( mpz_sgn( MPI( c ) ) > 0 )
     54            mpz_fdiv_q( thempi, thempi, MPI( c ) );
    5555        else
    56             mpz_cdiv_q( &thempi, &thempi, &MPI( c ) );
     56            mpz_cdiv_q( thempi, thempi, MPI( c ) );
    5757        return normalizeMyself();
    5858    }
     
    7070
    7171    if ( cf_glob_switches.isOn( SW_RATIONAL ) ) {
    72         MP_INT n, d;
     72        mpz_t n, d;
    7373        if ( invert ) {
    74             mpz_init_set_si( &n, intC );
    75             mpz_init_set( &d, &thempi );
    76         } else {
    77             mpz_init_set( &n, &thempi );
    78             mpz_init_set_si( &d, intC );
     74            mpz_init_set_si( n, intC );
     75            mpz_init_set( d, thempi );
     76        } else {
     77            mpz_init_set( n, thempi );
     78            mpz_init_set_si( d, intC );
    7979        }
    8080        if ( deleteObject() ) delete this;
     
    8484
    8585    if ( invert ) {
    86         int mpiSign = mpz_sgn( &thempi );
     86        int mpiSign = mpz_sgn( thempi );
    8787        if ( deleteObject() ) delete this;
    8888        if ( intC >= 0 )
     
    9292    } else if ( getRefCount() > 1 ) {
    9393        decRefCount();
    94         MP_INT mpiResult;
    95         mpz_init( &mpiResult );
     94        mpz_t mpiResult;
     95        mpz_init( mpiResult );
    9696        if ( intC > 0 )
    97             mpz_fdiv_q_ui( &mpiResult, &thempi, intC );
     97            mpz_fdiv_q_ui( mpiResult, thempi, intC );
    9898        else {
    99             mpz_fdiv_q_ui( &mpiResult, &thempi, -intC );
    100             mpz_neg( &mpiResult, &mpiResult );
     99            mpz_fdiv_q_ui( mpiResult, thempi, -intC );
     100            mpz_neg( mpiResult, mpiResult );
    101101        }
    102102        return normalizeMPI( mpiResult );
    103103    } else {
    104104        if ( intC > 0 )
    105             mpz_fdiv_q_ui( &thempi, &thempi, intC );
     105            mpz_fdiv_q_ui( thempi, thempi, intC );
    106106        else {
    107             mpz_fdiv_q_ui( &thempi, &thempi, -intC );
    108             mpz_neg( &thempi, &thempi );
     107            mpz_fdiv_q_ui( thempi, thempi, -intC );
     108            mpz_neg( thempi, thempi );
    109109        }
    110110        return normalizeMyself();
     
    128128    if ( getRefCount() > 1 ) {
    129129        deleteObject();
    130         MP_INT mpiResult;
    131         mpz_init( &mpiResult );
    132         mpz_divexact( &mpiResult, &thempi, &MPI( c ) );
     130        mpz_t mpiResult;
     131        mpz_init( mpiResult );
     132        mpz_divexact( mpiResult, thempi, MPI( c ) );
    133133        return normalizeMPI( mpiResult );
    134134    } else {
    135         mpz_divexact( &thempi, &thempi, &MPI( c ) );
     135        mpz_divexact( thempi, thempi, MPI( c ) );
    136136        return normalizeMyself();
    137137    }
     
    154154    } else if ( getRefCount() > 1 ) {
    155155        deleteObject();
    156         MP_INT mpiC;
    157         MP_INT mpiResult;
    158         mpz_init_set_si( &mpiC, imm2int( c ) );
    159         mpz_init( &mpiResult );
    160         mpz_divexact( &mpiResult, &thempi, &mpiC );
    161         mpz_clear( &mpiC );
     156        mpz_t mpiC;
     157        mpz_t mpiResult;
     158        mpz_init_set_si( mpiC, imm2int( c ) );
     159        mpz_init( mpiResult );
     160        mpz_divexact( mpiResult, thempi, mpiC );
     161        mpz_clear( mpiC );
    162162        return normalizeMPI( mpiResult );
    163163    } else {
    164         MP_INT mpiC;
    165         mpz_init_set_si( &mpiC, imm2int( c ) );
    166         mpz_divexact( &thempi, &thempi, &mpiC );
    167         mpz_clear( &mpiC );
     164        mpz_t mpiC;
     165        mpz_init_set_si( mpiC, imm2int( c ) );
     166        mpz_divexact( thempi, thempi, mpiC );
     167        mpz_clear( mpiC );
    168168        return normalizeMyself();
    169169    }
     
    186186    if ( getRefCount() > 1 ) {
    187187        decRefCount();
    188         MP_INT mpiResult;
    189         mpz_init( &mpiResult );
    190         mpz_mod( &mpiResult, &thempi, &MPI( c ) );
     188        mpz_t mpiResult;
     189        mpz_init( mpiResult );
     190        mpz_mod( mpiResult, thempi, MPI( c ) );
    191191        return uiNormalizeMPI( mpiResult );
    192192    } else {
    193         mpz_mod( &thempi, &thempi, &MPI( c ) );
     193        mpz_mod( thempi, thempi, MPI( c ) );
    194194        return uiNormalizeMyself();
    195195    }
     
    217217        } else {
    218218            // no checks for refCount == 1 are done.  It is not worth ...
    219             MP_INT mpiResult;
    220             mpz_init_set( &mpiResult, &thempi );
    221             mpz_abs( &mpiResult, &mpiResult );
    222             mpz_sub_ui( &mpiResult, &mpiResult, -intC );
     219            mpz_t mpiResult;
     220            mpz_init_set( mpiResult, thempi );
     221            mpz_abs( mpiResult, mpiResult );
     222            mpz_sub_ui( mpiResult, mpiResult, -intC );
    223223            if ( deleteObject() ) delete this;
    224224            return uiNormalizeMPI( mpiResult );
    225225        }
    226226    } else {
    227         MP_INT dummy;
    228         mpz_init( &dummy );
    229         InternalCF * result = int2imm( mpz_mod_ui( &dummy, &thempi, tabs( intC ) ) );
    230         mpz_clear( &dummy );
     227        mpz_t dummy;
     228        mpz_init( dummy );
     229        InternalCF * result = int2imm( mpz_mod_ui( dummy, thempi, tabs( intC ) ) );
     230        mpz_clear( dummy );
    231231        if ( deleteObject() ) delete this;
    232232        return result;
     
    265265
    266266    if ( cf_glob_switches.isOn( SW_RATIONAL ) ) {
    267         MP_INT n, d;
    268         mpz_init_set( &n, &thempi );
    269         mpz_init_set( &d, &MPI( c ) );
     267        mpz_t n, d;
     268        mpz_init_set( n, thempi );
     269        mpz_init_set( d, MPI( c ) );
    270270        InternalRational * result = new InternalRational( n, d );
    271271        quot = result->normalize_myself();
     
    274274    }
    275275
    276     MP_INT q;
    277     MP_INT r;
    278     mpz_init( &q ); mpz_init( &r );
    279     if ( mpz_sgn( &MPI( c ) ) > 0 )
    280         mpz_fdiv_qr( &q, &r, &thempi, &MPI( c ) );
     276    mpz_t q;
     277    mpz_t r;
     278    mpz_init( q ); mpz_init( r );
     279    if ( mpz_sgn( MPI( c ) ) > 0 )
     280        mpz_fdiv_qr( q, r, thempi, MPI( c ) );
    281281    else
    282         mpz_cdiv_qr( &q, &r, &thempi, &MPI( c ) );
     282        mpz_cdiv_qr( q, r, thempi, MPI( c ) );
    283283
    284284    quot = normalizeMPI( q );
     
    297297
    298298    if ( cf_glob_switches.isOn( SW_RATIONAL ) ) {
    299         MP_INT n, d;
     299        mpz_t n, d;
    300300        if ( invert ) {
    301             mpz_init_set_si( &n, intC );
    302             mpz_init_set( &d, &thempi );
    303         } else {
    304             mpz_init_set( &n, &thempi );
    305             mpz_init_set_si( &d, intC );
     301            mpz_init_set_si( n, intC );
     302            mpz_init_set( d, thempi );
     303        } else {
     304            mpz_init_set( n, thempi );
     305            mpz_init_set_si( d, intC );
    306306        }
    307307        InternalRational * result = new InternalRational( n, d );
     
    316316            quot = int2imm( 0 );
    317317        } else {
    318             MP_INT mpiResult;
    319             mpz_init_set( &mpiResult, &thempi );
    320             mpz_abs( &mpiResult, &mpiResult );
    321             mpz_sub_ui( &mpiResult, &mpiResult, -intC );
     318            mpz_t mpiResult;
     319            mpz_init_set( mpiResult, thempi );
     320            mpz_abs( mpiResult, mpiResult );
     321            mpz_sub_ui( mpiResult, mpiResult, -intC );
    322322            rem = uiNormalizeMPI( mpiResult );
    323             quot = int2imm( -mpz_sgn( &thempi ) );
    324         }
    325     } else {
    326         MP_INT q;
    327         MP_INT dummy;
    328         mpz_init( &q ); mpz_init( &dummy );
     323            quot = int2imm( -mpz_sgn( thempi ) );
     324        }
     325    } else {
     326        mpz_t q;
     327        mpz_t dummy;
     328        mpz_init( q ); mpz_init( dummy );
    329329        if ( intC > 0 ) {
    330             rem = int2imm( mpz_fdiv_qr_ui( &q, &dummy, &thempi, intC ) );
     330            rem = int2imm( mpz_fdiv_qr_ui( q, dummy, thempi, intC ) );
    331331            quot = normalizeMPI( q );
    332332        } else {
    333             rem = int2imm( mpz_fdiv_qr_ui( &q, &dummy, &thempi, -intC ) );
    334             mpz_neg( &q, &q );
     333            rem = int2imm( mpz_fdiv_qr_ui( q, dummy, thempi, -intC ) );
     334            mpz_neg( q, q );
    335335            quot = normalizeMPI( q );
    336336        }
    337         mpz_clear( &dummy );
     337        mpz_clear( dummy );
    338338    }
    339339}
  • factory/int_pp.cc

    r1c48503 ra52291  
    1212#include "imm.h"
    1313
    14 MP_INT InternalPrimePower::primepow;
    15 MP_INT InternalPrimePower::primepowhalf;
     14mpz_t InternalPrimePower::primepow;
     15mpz_t InternalPrimePower::primepowhalf;
    1616int InternalPrimePower::prime;
    1717int InternalPrimePower::exp;
     
    2121InternalPrimePower::InternalPrimePower()
    2222{
    23     mpz_init( &thempi );
     23    mpz_init( thempi );
    2424}
    2525
    2626InternalPrimePower::InternalPrimePower( const int i )
    2727{
    28     mpz_init_set_si( &thempi, i );
    29     if ( mpz_cmp_si( &thempi, 0 ) < 0 ) {
    30         mpz_neg( &thempi, &thempi );
    31         mpz_mod( &thempi, &thempi, &primepow );
    32         mpz_sub( &thempi, &primepow, &thempi );
     28    mpz_init_set_si( thempi, i );
     29    if ( mpz_cmp_si( thempi, 0 ) < 0 ) {
     30        mpz_neg( thempi, thempi );
     31        mpz_mod( thempi, thempi, primepow );
     32        mpz_sub( thempi, primepow, thempi );
    3333    }
    3434    else
    35         mpz_mod( &thempi, &thempi, &primepow );
    36 }
    37 
    38 InternalPrimePower::InternalPrimePower( const MP_INT & mpi ) : thempi( mpi ) {}
     35        mpz_mod( thempi, thempi, primepow );
     36}
     37
     38InternalPrimePower::InternalPrimePower( const mpz_ptr mpi) { thempi[0]=*mpi;}
    3939
    4040InternalPrimePower::InternalPrimePower( const char * str, const int base )
    4141{
    42     mpz_init_set_str( &thempi, str, base );
    43     if ( mpz_cmp_si( &thempi, 0 ) < 0 ) {
    44         mpz_neg( &thempi, &thempi );
    45         mpz_mod( &thempi, &thempi, &primepow );
    46         mpz_sub( &thempi, &primepow, &thempi );
     42    mpz_init_set_str( thempi, str, base );
     43    if ( mpz_cmp_si( thempi, 0 ) < 0 ) {
     44        mpz_neg( thempi, thempi );
     45        mpz_mod( thempi, thempi, primepow );
     46        mpz_sub( thempi, primepow, thempi );
    4747    }
    4848    else
    49         mpz_mod( &thempi, &thempi, &primepow );
     49        mpz_mod( thempi, thempi, primepow );
    5050}
    5151
    5252InternalPrimePower::~InternalPrimePower()
    5353{
    54     mpz_clear( &thempi );
     54    mpz_clear( thempi );
    5555}
    5656
    5757InternalCF* InternalPrimePower::deepCopyObject() const
    5858{
    59     MP_INT dummy;
    60     mpz_init_set( &dummy, &thempi );
     59    mpz_t dummy;
     60    mpz_init_set( dummy, thempi );
    6161    return new InternalPrimePower( dummy );
    6262}
     
    6565{
    6666    ASSERT( getRefCount() == 1, "illegal operation" );
    67     if ( mpz_cmp_si( &thempi, 0 ) < 0 ) {
    68         mpz_neg( &thempi, &thempi );
    69         mpz_mod( &thempi, &thempi, &primepow );
    70         mpz_sub( &thempi, &primepow, &thempi );
     67    if ( mpz_cmp_si( thempi, 0 ) < 0 ) {
     68        mpz_neg( thempi, thempi );
     69        mpz_mod( thempi, thempi, primepow );
     70        mpz_sub( thempi, primepow, thempi );
    7171    }
    7272    else
    73         mpz_mod( &thempi, &thempi, &primepow );
     73        mpz_mod( thempi, thempi, primepow );
    7474    return this;
    7575}
     
    7777int InternalPrimePower::initialize()
    7878{
    79     mpz_init_set_si( &primepow, 3 );
    80     mpz_init_set_si( &primepowhalf, 1 );
     79    mpz_init_set_si( primepow, 3 );
     80    mpz_init_set_si( primepowhalf, 1 );
    8181    prime = 3;
    8282    exp = 1;
     
    8989    ASSERT( p > 1 && k > 0, "illegal prime power" );
    9090    if ( p != prime || k != exp ) {
    91         mpz_set_si( &primepow, p );
    92         mpz_pow_ui( &primepow, &primepow, (unsigned int)k );
    93         mpz_fdiv_q_ui( &primepowhalf, &primepow, 2 );
     91        mpz_set_si( primepow, p );
     92        mpz_pow_ui( primepow, primepow, (unsigned int)k );
     93        mpz_fdiv_q_ui( primepowhalf, primepow, 2 );
    9494        prime = p;
    9595        exp = k;
     
    112112void InternalPrimePower::print( OSTREAM & os, char * c )
    113113{
    114     if ( *c == '*' && mpz_cmp_si( &thempi, 1 ) == 0 )
     114    if ( *c == '*' && mpz_cmp_si( thempi, 1 ) == 0 )
    115115        os << c+1;
    116     else if ( *c == '*' && mpz_cmp_si( &thempi, -1 ) == 0 )
     116    else if ( *c == '*' && mpz_cmp_si( thempi, -1 ) == 0 )
    117117        os << '-' << c+1;
    118118    else {
    119         char * str = new char[mpz_sizeinbase( &thempi, 10 ) + 2];
    120         str = mpz_get_str( str, 10, &thempi );
     119        char * str = new char[mpz_sizeinbase( thempi, 10 ) + 2];
     120        str = mpz_get_str( str, 10, thempi );
    121121        os << str << c;
    122122        delete [] str;
     
    130130InternalPrimePower::isOne () const
    131131{
    132     return mpz_cmp_ui( &thempi, 1 ) == 0;
     132    return mpz_cmp_ui( thempi, 1 ) == 0;
    133133}
    134134
     
    136136InternalPrimePower::isZero () const
    137137{
    138     return mpz_sgn( &thempi ) == 0;
     138    return mpz_sgn( thempi ) == 0;
    139139}
    140140//}}}
     
    168168    if ( getRefCount() > 1 ) {
    169169        decRefCount();
    170         MP_INT dummy;
    171         mpz_init( &dummy );
    172         mpz_sub( &dummy, &primepow, &thempi );
     170        mpz_t dummy;
     171        mpz_init( dummy );
     172        mpz_sub( dummy, primepow, thempi );
    173173        return new InternalPrimePower( dummy );
    174174    } else {
    175         mpz_sub( &thempi, &primepow, &thempi );
     175        mpz_sub( thempi, primepow, thempi );
    176176        return this;
    177177    }
     
    184184    if ( getRefCount() > 1 ) {
    185185        decRefCount();
    186         MP_INT dummy;
    187         mpz_init( &dummy );
    188         mpz_add( &dummy, &thempi, &MPI( c ) );
    189         if ( mpz_cmp( &dummy, &primepow ) >= 0 )
    190             mpz_sub( &dummy, &dummy, &primepow );
     186        mpz_t dummy;
     187        mpz_init( dummy );
     188        mpz_add( dummy, thempi, MPI( c ) );
     189        if ( mpz_cmp( dummy, primepow ) >= 0 )
     190            mpz_sub( dummy, dummy, primepow );
    191191        return new InternalPrimePower( dummy );
    192192    }
    193193    else {
    194         mpz_add( &thempi, &thempi, &MPI( c ) );
    195         if ( mpz_cmp( &thempi, &primepow ) >= 0 )
    196             mpz_sub( &thempi, &thempi, &primepow );
     194        mpz_add( thempi, thempi, MPI( c ) );
     195        if ( mpz_cmp( thempi, primepow ) >= 0 )
     196            mpz_sub( thempi, thempi, primepow );
    197197        return this;
    198198    }
     
    203203    if ( getRefCount() > 1 ) {
    204204        decRefCount();
    205         MP_INT dummy;
    206         mpz_init( &dummy );
    207         mpz_sub( &dummy, &thempi, &MPI( c ) );
    208         if ( mpz_cmp_si( &dummy, 0 ) < 0 )
    209             mpz_add( &dummy, &dummy, &primepow );
     205        mpz_t dummy;
     206        mpz_init( dummy );
     207        mpz_sub( dummy, thempi, MPI( c ) );
     208        if ( mpz_cmp_si( dummy, 0 ) < 0 )
     209            mpz_add( dummy, dummy, primepow );
    210210        return new InternalPrimePower( dummy );
    211211    }
    212212    else {
    213         mpz_sub( &thempi, &thempi, &MPI( c ) );
    214         if ( mpz_cmp_si( &thempi, 0 ) < 0 )
    215             mpz_add( &thempi, &thempi, &primepow );
     213        mpz_sub( thempi, thempi, MPI( c ) );
     214        if ( mpz_cmp_si( thempi, 0 ) < 0 )
     215            mpz_add( thempi, thempi, primepow );
    216216        return this;
    217217    }
     
    222222    if ( getRefCount() > 1 ) {
    223223        decRefCount();
    224         MP_INT dummy;
    225         mpz_init( &dummy );
    226         mpz_mul( &dummy, &thempi, &MPI( c ) );
    227         mpz_mod( &dummy, &dummy, &primepow );
     224        mpz_t dummy;
     225        mpz_init( dummy );
     226        mpz_mul( dummy, thempi, MPI( c ) );
     227        mpz_mod( dummy, dummy, primepow );
    228228        return new InternalPrimePower( dummy );
    229229    }
    230230    else {
    231         mpz_mul( &thempi, &thempi, &MPI( c ) );
    232         mpz_mod( &thempi, &thempi, &primepow );
     231        mpz_mul( thempi, thempi, MPI( c ) );
     232        mpz_mod( thempi, thempi, primepow );
    233233        return this;
    234234    }
     
    248248    if ( getRefCount() > 1 ) {
    249249        decRefCount();
    250         MP_INT dummy, a, b;
    251         mpz_init( &dummy ); mpz_init( &a ); mpz_init( &b );
    252         mpz_gcdext( &dummy, &a, &b, &primepow, &MPI( c ) );
    253         ASSERT( mpz_cmp_si( &dummy, 1 ) == 0, "illegal inversion" );
    254         mpz_clear( &dummy ); mpz_clear( &a );
    255         if ( mpz_cmp_si( &b, 0 ) < 0 )
    256             mpz_add( &b, &b, &primepow );
    257         mpz_mul( &b, &b, &thempi );
    258         mpz_mod( &b, &b, &primepow );
     250        mpz_t dummy, a, b;
     251        mpz_init( dummy ); mpz_init( a ); mpz_init( b );
     252        mpz_gcdext( dummy, a, b, primepow, MPI( c ) );
     253        ASSERT( mpz_cmp_si( dummy, 1 ) == 0, "illegal inversion" );
     254        mpz_clear( dummy ); mpz_clear( a );
     255        if ( mpz_cmp_si( b, 0 ) < 0 )
     256            mpz_add( b, b, primepow );
     257        mpz_mul( b, b, thempi );
     258        mpz_mod( b, b, primepow );
    259259        return new InternalPrimePower( b );
    260260    }
    261261    else {
    262         MP_INT dummy, a, b;
    263         mpz_init( &dummy ); mpz_init( &a ); mpz_init( &b );
    264         mpz_gcdext( &dummy, &a, &b, &primepow, &MPI( c ) );
    265         ASSERT( mpz_cmp_si( &dummy, 1 ) == 0, "illegal inversion" );
    266         if ( mpz_cmp_si( &b, 0 ) < 0 )
    267             mpz_add( &b, &b, &primepow );
    268         mpz_mul( &thempi, &b, &thempi );
    269         mpz_mod( &thempi, &thempi, &primepow );
    270         mpz_clear( &dummy ); mpz_clear( &a ); mpz_clear( &b );
     262        mpz_t dummy, a, b;
     263        mpz_init( dummy ); mpz_init( a ); mpz_init( b );
     264        mpz_gcdext( dummy, a, b, primepow, MPI( c ) );
     265        ASSERT( mpz_cmp_si( dummy, 1 ) == 0, "illegal inversion" );
     266        if ( mpz_cmp_si( b, 0 ) < 0 )
     267            mpz_add( b, b, primepow );
     268        mpz_mul( thempi, b, thempi );
     269        mpz_mod( thempi, thempi, primepow );
     270        mpz_clear( dummy ); mpz_clear( a ); mpz_clear( b );
    271271        return this;
    272272    }
     
    295295    }
    296296    else {
    297         MP_INT dummy, a, b;
    298         mpz_init( &dummy ); mpz_init( &a ); mpz_init( &b );
    299         mpz_gcdext( &dummy, &a, &b, &primepow, &MPI( c ) );
    300         ASSERT( mpz_cmp_si( &dummy, 1 ) == 0, "illegal inversion" );
    301         mpz_clear( &dummy ); mpz_clear( &a );
    302         if ( mpz_cmp_si( &b, 0 ) < 0 )
    303             mpz_add( &b, &b, &primepow );
    304         mpz_mul( &b, &b, &thempi );
    305         mpz_mod( &b, &b, &primepow );
     297        mpz_t dummy, a, b;
     298        mpz_init( dummy ); mpz_init( a ); mpz_init( b );
     299        mpz_gcdext( dummy, a, b, primepow, MPI( c ) );
     300        ASSERT( mpz_cmp_si( dummy, 1 ) == 0, "illegal inversion" );
     301        mpz_clear( dummy ); mpz_clear( a );
     302        if ( mpz_cmp_si( b, 0 ) < 0 )
     303            mpz_add( b, b, primepow );
     304        mpz_mul( b, b, thempi );
     305        mpz_mod( b, b, primepow );
    306306        quot = new InternalPrimePower( b );
    307307        rem = CFFactory::basic( 0 );
     
    322322{
    323323    ASSERT( ! ::is_imm( c ) && c->levelcoeff() == PrimePowerDomain, "incompatible base coefficients" );
    324     return mpz_cmp( &thempi, &MPI( c ) );
     324    return mpz_cmp( thempi, MPI( c ) );
    325325}
    326326
     
    398398InternalPrimePower::intval () const
    399399{
    400   return (int)mpz_get_si( &thempi );
     400  return (int)mpz_get_si( thempi );
    401401}
    402402
     
    404404InternalPrimePower::intmod( int p ) const
    405405{
    406   return (int)mpz_fdiv_ui( &thempi, (unsigned long)p );
     406  return (int)mpz_fdiv_ui( thempi, (unsigned long)p );
    407407}
    408408
     
    412412InternalPrimePower::sign () const
    413413{
    414     return mpz_sgn( &thempi );
     414    return mpz_sgn( thempi );
    415415}
    416416//}}}
  • factory/int_pp.h

    r1c48503 ra52291  
    2727{
    2828private:
    29     MP_INT thempi;
     29    mpz_t thempi;
    3030    static int initialized;
    3131    static int prime;
    3232    static int exp;
    33     static MP_INT primepow;
    34     static MP_INT primepowhalf;
     33    static mpz_t primepow;
     34    static mpz_t primepowhalf;
    3535    static int initialize();
    36     static MP_INT & MPI( const InternalCF * const c );
     36    static mpz_ptr MPI( const InternalCF * const c );
    3737public:
    3838    InternalPrimePower();
     
    4343    InternalPrimePower( const int i );
    4444    InternalPrimePower( const char * str, const int base=10 );
    45     InternalPrimePower( const MP_INT & );
     45    InternalPrimePower( const mpz_ptr );
    4646    ~InternalPrimePower();
    4747    InternalCF* deepCopyObject() const;
     
    9494
    9595    int sign() const;
    96     friend MP_INT getmpi ( InternalCF * value, bool symmetric );
     96    friend mpz_ptr getmpi ( InternalCF * value, bool symmetric );
    9797};
    9898
    99 inline MP_INT & InternalPrimePower::MPI( const InternalCF * const c )
     99inline mpz_ptr InternalPrimePower::MPI( const InternalCF * const c )
    100100{
    101101    return (((InternalPrimePower*)c)->thempi);
  • factory/int_rat.cc

    r1c48503 ra52291  
    3333InternalRational::InternalRational()
    3434{
    35     mpz_init( &_num );
    36     mpz_init_set_si( &_den, 1 );
     35    mpz_init( _num );
     36    mpz_init_set_si( _den, 1 );
    3737}
    3838
    3939InternalRational::InternalRational( const int i )
    4040{
    41     mpz_init_set_si( &_num, i );
    42     mpz_init_set_si( &_den, 1 );
     41    mpz_init_set_si( _num, i );
     42    mpz_init_set_si( _den, 1 );
    4343}
    4444
     
    4848    if ( n == 0 )
    4949    {
    50         mpz_init_set_si( &_num, 0 );
    51         mpz_init_set_si( &_den, 1 );
     50        mpz_init_set_si( _num, 0 );
     51        mpz_init_set_si( _den, 1 );
    5252    }
    5353    else
    5454    {
    5555        int g = intgcd( n, d );
    56         if ( d < 0 ) g= -g;
    57         mpz_init_set_si( &_num, n / g );
    58         mpz_init_set_si( &_den, d / g );
     56        if ( d < 0 )
     57        {
     58          mpz_init_set_si( _num, -n / g );
     59          mpz_init_set_si( _den, -d / g );
     60        }
     61        else
     62        {
     63          mpz_init_set_si( _num, n / g );
     64          mpz_init_set_si( _den, d / g );
     65        }
    5966    }
    6067}
     
    6471    // sollte nicht gebraucht werden !!!
    6572    ASSERT( 0, "fatal error" );
    66     mpz_init( &_num );
    67     mpz_init( &_den );
    68 }
    69 
    70 InternalRational::InternalRational( const MP_INT &n ) : _num(n)
    71 {
    72     mpz_init_set_si( &_den, 1 );
    73 }
    74 
    75 InternalRational::InternalRational( const MP_INT &n, const MP_INT &d ) : _num(n), _den(d)
    76 {
     73    mpz_init( _num );
     74    mpz_init( _den );
     75}
     76
     77//InternalRational::InternalRational( const mpz_ptr n ) : _num(n)
     78//{
     79//    mpz_init_set_si( _den, 1 );
     80//}
     81
     82InternalRational::InternalRational( const mpz_ptr n )
     83{
     84    _num[0]=*n;
     85    mpz_init_set_si( _den, 1 );
     86}
     87
     88InternalRational::InternalRational( const mpz_ptr n, const mpz_ptr d )
     89{
     90  _num[0]=*n;
     91  _den[0]=*d;
    7792}
    7893
    7994InternalRational::~InternalRational()
    8095{
    81     mpz_clear( &_num );
    82     mpz_clear( &_den );
     96    mpz_clear( _num );
     97    mpz_clear( _den );
    8398}
    8499
    85100InternalCF* InternalRational::deepCopyObject() const
    86101{
    87     MP_INT dummy_num;
    88     MP_INT dummy_den;
    89     mpz_init_set( &dummy_num, &_num );
    90     mpz_init_set( &dummy_den, &_den );
     102    mpz_t dummy_num;
     103    mpz_t dummy_den;
     104    mpz_init_set( dummy_num, _num );
     105    mpz_init_set( dummy_den, _den );
    91106    return new InternalRational( dummy_num, dummy_den );
    92107}
     
    95110void InternalRational::print( OSTREAM & os, char * c )
    96111{
    97     char * str = new char[mpz_sizeinbase( &_num, 10 ) + 2];
    98     str = mpz_get_str( str, 10, &_num );
     112    char * str = new char[mpz_sizeinbase( _num, 10 ) + 2];
     113    str = mpz_get_str( str, 10, _num );
    99114    os << str << '/';
    100115    delete [] str;
    101     str = new char[mpz_sizeinbase( &_den, 10 ) + 2];
    102     str = mpz_get_str( str, 10, &_den );
     116    str = new char[mpz_sizeinbase( _den, 10 ) + 2];
     117    str = mpz_get_str( str, 10, _den );
    103118    os << str << c;
    104119    delete [] str;
     
    108123bool InternalRational::is_imm() const
    109124{
    110     return mpz_cmp_si( &_den, 1 ) == 0 && mpz_is_imm( &_num );
     125    return mpz_cmp_si( _den, 1 ) == 0 && mpz_is_imm( _num );
    111126}
    112127
     
    131146InternalCF * InternalRational::num ()
    132147{
    133     if ( mpz_is_imm( &_num ) )
    134     {
    135         InternalCF * res = int2imm( mpz_get_si( &_num ) );
     148    if ( mpz_is_imm( _num ) )
     149    {
     150        InternalCF * res = int2imm( mpz_get_si( _num ) );
    136151        return res;
    137152    }
    138153    else
    139154    {
    140         MP_INT dummy;
    141         mpz_init_set( &dummy, &_num );
     155        mpz_t dummy;
     156        mpz_init_set( dummy, _num );
    142157        return new InternalInteger( dummy );
    143158    }
     
    146161InternalCF * InternalRational::den ()
    147162{
    148     if ( mpz_is_imm( &_den ) )
    149     {
    150         InternalCF * res = int2imm( mpz_get_si( &_den ) );
     163    if ( mpz_is_imm( _den ) )
     164    {
     165        InternalCF * res = int2imm( mpz_get_si( _den ) );
    151166        return res;
    152167    }
    153168    else
    154169    {
    155         MP_INT dummy;
    156         mpz_init_set( &dummy, &_den );
     170        mpz_t dummy;
     171        mpz_init_set( dummy, _den );
    157172        return new InternalInteger( dummy );
    158173    }
     
    168183    {
    169184        decRefCount();
    170         MP_INT dummy_num;
    171         MP_INT dummy_den;
    172         mpz_init_set( &dummy_num, &_num );
    173         mpz_init_set( &dummy_den, &_den );
    174         mpz_neg( &dummy_num, &dummy_num );
     185        mpz_t dummy_num;
     186        mpz_t dummy_den;
     187        mpz_init_set( dummy_num, _num );
     188        mpz_init_set( dummy_den, _den );
     189        mpz_neg( dummy_num, dummy_num );
    175190        return new InternalRational( dummy_num, dummy_den );
    176191    }
    177192    else
    178193    {
    179         mpz_neg( &_num, &_num );
     194        mpz_neg( _num, _num );
    180195        return this;
    181196    }
     
    186201{
    187202    ASSERT( ! ::is_imm( c ) && c->levelcoeff() == RationalDomain, "illegal domain" );
    188     MP_INT n, d, g;
    189 
    190     mpz_init( &g ); mpz_init( &n ); mpz_init( &d );
    191     mpz_gcd( &g, &_den, &MPQDEN( c ) );
    192 
    193     if ( mpz_cmp_si( &g, 1 ) == 0 )
    194     {
    195       mpz_mul( &n, &_den, &MPQNUM( c ) );
    196       mpz_mul( &g, &_num, &MPQDEN( c ) );
    197       mpz_add( &n, &n, &g );
    198       mpz_mul( &d, &_den, &MPQDEN( c ) );
    199     }
    200     else
    201     {
    202       MP_INT tmp1;
    203       MP_INT tmp2;
    204       mpz_init( &tmp1 );
    205       mpz_divexact( &tmp1, &_den, &g );
    206       mpz_init( &tmp2 );
    207       mpz_divexact( &tmp2, &MPQDEN( c ), &g );
    208       mpz_mul( &d, &tmp2, &_den );
    209       mpz_mul( &tmp2, &tmp2, &_num );
    210       mpz_mul( &tmp1, &tmp1, &MPQNUM( c ) );
    211       mpz_add( &n, &tmp1, &tmp2 );
    212       mpz_gcd( &g, &n, &d );
    213       if ( mpz_cmp_si( &g, 1 ) != 0 )
     203    mpz_t n, d, g;
     204
     205    mpz_init( g ); mpz_init( n ); mpz_init( d );
     206    mpz_gcd( g, _den, MPQDEN( c ) );
     207
     208    if ( mpz_cmp_si( g, 1 ) == 0 )
     209    {
     210      mpz_mul( n, _den, MPQNUM( c ) );
     211      mpz_mul( g, _num, MPQDEN( c ) );
     212      mpz_add( n, n, g );
     213      mpz_mul( d, _den, MPQDEN( c ) );
     214    }
     215    else
     216    {
     217      mpz_t tmp1;
     218      mpz_t tmp2;
     219      mpz_init( tmp1 );
     220      mpz_divexact( tmp1, _den, g );
     221      mpz_init( tmp2 );
     222      mpz_divexact( tmp2, MPQDEN( c ), g );
     223      mpz_mul( d, tmp2, _den );
     224      mpz_mul( tmp2, tmp2, _num );
     225      mpz_mul( tmp1, tmp1, MPQNUM( c ) );
     226      mpz_add( n, tmp1, tmp2 );
     227      mpz_gcd( g, n, d );
     228      if ( mpz_cmp_si( g, 1 ) != 0 )
    214229      {
    215           mpz_divexact( &n, &n, &g );
    216           mpz_divexact( &d, &d, &g );
     230          mpz_divexact( n, n, g );
     231          mpz_divexact( d, d, g );
    217232      }
    218       mpz_clear( &tmp1 );
    219       mpz_clear( &tmp2 );
    220     }
    221     mpz_clear( &g );
     233      mpz_clear( tmp1 );
     234      mpz_clear( tmp2 );
     235    }
     236    mpz_clear( g );
    222237    if ( deleteObject() ) delete this;
    223     if ( mpz_cmp_si( &d, 1 ) == 0 )
    224     {
    225       mpz_clear( &d );
    226       if ( mpz_is_imm( &n ) )
     238    if ( mpz_cmp_si( d, 1 ) == 0 )
     239    {
     240      mpz_clear( d );
     241      if ( mpz_is_imm( n ) )
    227242      {
    228           InternalCF * res = int2imm( mpz_get_si( &n ) );
    229           mpz_clear( &n );
     243          InternalCF * res = int2imm( mpz_get_si( n ) );
     244          mpz_clear( n );
    230245          return res;
    231246      }
     
    244259{
    245260    ASSERT( ! ::is_imm( c ) && c->levelcoeff() == RationalDomain, "illegal domain" );
    246     MP_INT n, d, g;
    247 
    248     mpz_init( &g ); mpz_init( &n ); mpz_init( &d );
    249     mpz_gcd( &g, &_den, &MPQDEN( c ) );
    250 
    251     if ( mpz_cmp_si( &g, 1 ) == 0 )
    252     {
    253         mpz_mul( &n, &_den, &MPQNUM( c ) );
    254         mpz_mul( &g, &_num, &MPQDEN( c ) );
    255         mpz_sub( &n, &g, &n );
    256         mpz_mul( &d, &_den, &MPQDEN( c ) );
    257     }
    258     else
    259     {
    260         MP_INT tmp1;
    261         MP_INT tmp2;
    262         mpz_init( &tmp1 );
    263         mpz_divexact( &tmp1, &_den, &g );
    264         mpz_init( &tmp2 );
    265         mpz_divexact( &tmp2, &MPQDEN( c ), &g );
    266         mpz_mul( &d, &tmp2, &_den );
    267         mpz_mul( &tmp2, &tmp2, &_num );
    268         mpz_mul( &tmp1, &tmp1, &MPQNUM( c ) );
    269         mpz_sub( &n, &tmp2, &tmp1 );
    270         mpz_gcd( &g, &n, &d );
    271         if ( mpz_cmp_si( &g, 1 ) != 0 )
    272         {
    273             mpz_divexact( &n, &n, &g );
    274             mpz_divexact( &d, &d, &g );
    275         }
    276         mpz_clear( &tmp1 );
    277         mpz_clear( &tmp2 );
    278     }
    279     mpz_clear( &g );
     261    mpz_t n, d, g;
     262
     263    mpz_init( g ); mpz_init( n ); mpz_init( d );
     264    mpz_gcd( g, _den, MPQDEN( c ) );
     265
     266    if ( mpz_cmp_si( g, 1 ) == 0 )
     267    {
     268        mpz_mul( n, _den, MPQNUM( c ) );
     269        mpz_mul( g, _num, MPQDEN( c ) );
     270        mpz_sub( n, g, n );
     271        mpz_mul( d, _den, MPQDEN( c ) );
     272    }
     273    else
     274    {
     275        mpz_t tmp1;
     276        mpz_t tmp2;
     277        mpz_init( tmp1 );
     278        mpz_divexact( tmp1, _den, g );
     279        mpz_init( tmp2 );
     280        mpz_divexact( tmp2, MPQDEN( c ), g );
     281        mpz_mul( d, tmp2, _den );
     282        mpz_mul( tmp2, tmp2, _num );
     283        mpz_mul( tmp1, tmp1, MPQNUM( c ) );
     284        mpz_sub( n, tmp2, tmp1 );
     285        mpz_gcd( g, n, d );
     286        if ( mpz_cmp_si( g, 1 ) != 0 )
     287        {
     288            mpz_divexact( n, n, g );
     289            mpz_divexact( d, d, g );
     290        }
     291        mpz_clear( tmp1 );
     292        mpz_clear( tmp2 );
     293    }
     294    mpz_clear( g );
    280295    if ( deleteObject() ) delete this;
    281     if ( mpz_cmp_si( &d, 1 ) == 0 )
    282     {
    283         mpz_clear( &d );
    284         if ( mpz_is_imm( &n ) )
    285         {
    286             InternalCF * res = int2imm( mpz_get_si( &n ) );
    287             mpz_clear( &n );
     296    if ( mpz_cmp_si( d, 1 ) == 0 )
     297    {
     298        mpz_clear( d );
     299        if ( mpz_is_imm( n ) )
     300        {
     301            InternalCF * res = int2imm( mpz_get_si( n ) );
     302            mpz_clear( n );
    288303            return res;
    289304        }
     
    300315{
    301316    ASSERT( ! ::is_imm( c ) && c->levelcoeff() == RationalDomain, "illegal domain" );
    302     MP_INT n, d;
    303     mpz_init( &n ); mpz_init( &d );
     317    mpz_t n, d;
     318    mpz_init( n ); mpz_init( d );
    304319
    305320    if ( this == c )
    306321    {
    307         mpz_mul( &n, &_num, &_num );
    308         mpz_mul( &d, &_den, &_den );
    309     }
    310     else
    311     {
    312         MP_INT g1, g2, tmp1, tmp2;
    313         mpz_init( &g1 ); mpz_init( &g2 );
    314         mpz_gcd( &g1, &_num, &MPQDEN( c ) );
    315         mpz_gcd( &g2, &_den, &MPQNUM( c ) );
    316         bool g1is1 = mpz_cmp_si( &g1, 1 ) == 0;
    317         bool g2is1 = mpz_cmp_si( &g2, 1 ) == 0;
    318         mpz_init( &tmp1 ); mpz_init( &tmp2 );
     322        mpz_mul( n, _num, _num );
     323        mpz_mul( d, _den, _den );
     324    }
     325    else
     326    {
     327        mpz_t g1, g2, tmp1, tmp2;
     328        mpz_init( g1 ); mpz_init( g2 );
     329        mpz_gcd( g1, _num, MPQDEN( c ) );
     330        mpz_gcd( g2, _den, MPQNUM( c ) );
     331        bool g1is1 = mpz_cmp_si( g1, 1 ) == 0;
     332        bool g2is1 = mpz_cmp_si( g2, 1 ) == 0;
     333        mpz_init( tmp1 ); mpz_init( tmp2 );
    319334        if ( ! g1is1 )
    320             mpz_divexact( &tmp1, &_num, &g1 );
    321         else
    322             mpz_set( &tmp1, &_num );
     335            mpz_divexact( tmp1, _num, g1 );
     336        else
     337            mpz_set( tmp1, _num );
    323338        if ( ! g2is1 )
    324             mpz_divexact( &tmp2, &MPQNUM( c ), &g2 );
    325         else
    326             mpz_set( &tmp2, &MPQNUM( c ) );
    327         mpz_mul( &n, &tmp1, &tmp2 );
     339            mpz_divexact( tmp2, MPQNUM( c ), g2 );
     340        else
     341            mpz_set( tmp2, MPQNUM( c ) );
     342        mpz_mul( n, tmp1, tmp2 );
    328343        if ( ! g1is1 )
    329             mpz_divexact( &tmp1, &MPQDEN( c ), &g1 );
    330         else
    331             mpz_set( &tmp1, &MPQDEN( c ) );
     344            mpz_divexact( tmp1, MPQDEN( c ), g1 );
     345        else
     346            mpz_set( tmp1, MPQDEN( c ) );
    332347        if ( ! g2is1 )
    333             mpz_divexact( &tmp2, &_den, &g2 );
    334         else
    335             mpz_set( &tmp2, &_den );
    336         mpz_mul( &d, &tmp1, &tmp2 );
    337         mpz_clear( &tmp1 ); mpz_clear( &tmp2 );
    338         mpz_clear( &g1 ); mpz_clear( &g2 );
     348            mpz_divexact( tmp2, _den, g2 );
     349        else
     350            mpz_set( tmp2, _den );
     351        mpz_mul( d, tmp1, tmp2 );
     352        mpz_clear( tmp1 ); mpz_clear( tmp2 );
     353        mpz_clear( g1 ); mpz_clear( g2 );
    339354    }
    340355    if ( deleteObject() ) delete this;
    341     if ( mpz_cmp_si( &d, 1 ) == 0 )
    342     {
    343         mpz_clear( &d );
    344         if ( mpz_is_imm( &n ) )
    345         {
    346             InternalCF * res = int2imm( mpz_get_si( &n ) );
    347             mpz_clear( &n );
     356    if ( mpz_cmp_si( d, 1 ) == 0 )
     357    {
     358        mpz_clear( d );
     359        if ( mpz_is_imm( n ) )
     360        {
     361            InternalCF * res = int2imm( mpz_get_si( n ) );
     362            mpz_clear( n );
    348363            return res;
    349364        }
     
    368383    else
    369384    {
    370         MP_INT n, d;
    371         MP_INT g1, g2, tmp1, tmp2;
    372         mpz_init( &n ); mpz_init( &d );
    373         mpz_init( &g1 ); mpz_init( &g2 );
    374         mpz_gcd( &g1, &_num, &MPQNUM( c ) );
    375         mpz_gcd( &g2, &_den, &MPQDEN( c ) );
    376         bool g1is1 = mpz_cmp_si( &g1, 1 ) == 0;
    377         bool g2is1 = mpz_cmp_si( &g2, 1 ) == 0;
    378         mpz_init( &tmp1 ); mpz_init( &tmp2 );
     385        mpz_t n, d;
     386        mpz_t g1, g2, tmp1, tmp2;
     387        mpz_init( n ); mpz_init( d );
     388        mpz_init( g1 ); mpz_init( g2 );
     389        mpz_gcd( g1, _num, MPQNUM( c ) );
     390        mpz_gcd( g2, _den, MPQDEN( c ) );
     391        bool g1is1 = mpz_cmp_si( g1, 1 ) == 0;
     392        bool g2is1 = mpz_cmp_si( g2, 1 ) == 0;
     393        mpz_init( tmp1 ); mpz_init( tmp2 );
    379394        if ( ! g1is1 )
    380             mpz_divexact( &tmp1, &_num, &g1 );
    381         else
    382             mpz_set( &tmp1, &_num );
     395            mpz_divexact( tmp1, _num, g1 );
     396        else
     397            mpz_set( tmp1, _num );
    383398        if ( ! g2is1 )
    384             mpz_divexact( &tmp2, &MPQDEN( c ), &g2 );
    385         else
    386             mpz_set( &tmp2, &MPQDEN( c ) );
    387         mpz_mul( &n, &tmp1, &tmp2 );
     399            mpz_divexact( tmp2, MPQDEN( c ), g2 );
     400        else
     401            mpz_set( tmp2, MPQDEN( c ) );
     402        mpz_mul( n, tmp1, tmp2 );
    388403        if ( ! g1is1 )
    389             mpz_divexact( &tmp1, &MPQNUM( c ), &g1 );
    390         else
    391             mpz_set( &tmp1, &MPQNUM( c ) );
     404            mpz_divexact( tmp1, MPQNUM( c ), g1 );
     405        else
     406            mpz_set( tmp1, MPQNUM( c ) );
    392407        if ( ! g2is1 )
    393             mpz_divexact( &tmp2, &_den, &g2 );
    394         else
    395             mpz_set( &tmp2, &_den );
    396         mpz_mul( &d, &tmp1, &tmp2 );
    397         mpz_clear( &tmp1 ); mpz_clear( &tmp2 );
    398         mpz_clear( &g1 ); mpz_clear( &g2 );
     408            mpz_divexact( tmp2, _den, g2 );
     409        else
     410            mpz_set( tmp2, _den );
     411        mpz_mul( d, tmp1, tmp2 );
     412        mpz_clear( tmp1 ); mpz_clear( tmp2 );
     413        mpz_clear( g1 ); mpz_clear( g2 );
    399414        if ( deleteObject() ) delete this;
    400         if ( mpz_cmp_si( &d, 0 ) < 0 )
    401         {
    402             mpz_neg( &d, &d );
    403             mpz_neg( &n, &n );
    404         }
    405         if ( mpz_cmp_si( &d, 1 ) == 0 )
    406         {
    407             mpz_clear( &d );
    408             if ( mpz_is_imm( &n ) )
     415        if ( mpz_cmp_si( d, 0 ) < 0 )
     416        {
     417            mpz_neg( d, d );
     418            mpz_neg( n, n );
     419        }
     420        if ( mpz_cmp_si( d, 1 ) == 0 )
     421        {
     422            mpz_clear( d );
     423            if ( mpz_is_imm( n ) )
    409424            {
    410                 InternalCF * res = int2imm( mpz_get_si( &n ) );
    411                 mpz_clear( &n );
     425                InternalCF * res = int2imm( mpz_get_si( n ) );
     426                mpz_clear( n );
    412427                return res;
    413428            }
     
    473488{
    474489    ASSERT( ! ::is_imm( c ) && c->levelcoeff() == RationalDomain, "incompatible base coefficients" );
    475     MP_INT dummy1, dummy2;
    476     mpz_init( &dummy1 ); mpz_init( &dummy2 );
    477     mpz_mul( &dummy1, &_num, &MPQDEN( c ) );
    478     mpz_mul( &dummy2, &_den, &MPQNUM( c ) );
    479     int result = mpz_cmp( &dummy1, &dummy2 );
    480     mpz_clear( &dummy1 ); mpz_clear( &dummy2 );
     490    mpz_t dummy1, dummy2;
     491    mpz_init( dummy1 ); mpz_init( dummy2 );
     492    mpz_mul( dummy1, _num, MPQDEN( c ) );
     493    mpz_mul( dummy2, _den, MPQNUM( c ) );
     494    int result = mpz_cmp( dummy1, dummy2 );
     495    mpz_clear( dummy1 ); mpz_clear( dummy2 );
    481496    return result;
    482497}
     
    488503    {
    489504        ASSERT( ::is_imm( c ) == INTMARK, "incompatible base coefficients" );
    490         MP_INT dummy;
    491         mpz_init_set_si( &dummy, imm2int( c ) );
    492         mpz_mul( &dummy, &dummy, &_den );
    493         int result = mpz_cmp( &_num, &dummy );
    494         mpz_clear( &dummy );
     505        mpz_t dummy;
     506        mpz_init_set_si( dummy, imm2int( c ) );
     507        mpz_mul( dummy, dummy, _den );
     508        int result = mpz_cmp( _num, dummy );
     509        mpz_clear( dummy );
    495510        return result;
    496511    }
     
    498513    {
    499514        ASSERT( c->levelcoeff() == IntegerDomain, "incompatible base coefficients" );
    500         MP_INT dummy;
    501         mpz_init( &dummy );
    502         mpz_mul( &dummy, &_den, &InternalInteger::MPI( c ) );
    503         int result = mpz_cmp( &_num, &dummy );
    504         mpz_clear( &dummy );
     515        mpz_t dummy;
     516        mpz_init( dummy );
     517        mpz_mul( dummy, _den, InternalInteger::MPI( c ) );
     518        int result = mpz_cmp( _num, dummy );
     519        mpz_clear( dummy );
    505520        return result;
    506521    }
     
    511526{
    512527    ASSERT( ::is_imm( c ) == INTMARK || ! ::is_imm( c ), "expected integer" );
    513     MP_INT n, d;
     528    mpz_t n, d;
    514529    if ( ::is_imm( c ) )
    515530    {
     
    519534        else
    520535        {
    521           mpz_init( &n );
     536          mpz_init( n );
    522537          if ( cc < 0 )
    523538          {
    524             mpz_mul_ui( &n, &_den, -cc );
    525             mpz_sub( &n, &_num, &n );
     539            mpz_mul_ui( n, _den, -cc );
     540            mpz_sub( n, _num, n );
    526541          }
    527542          else
    528543          {
    529             mpz_mul_ui( &n, &_den, cc );
    530             mpz_add( &n, &_num, &n );
     544            mpz_mul_ui( n, _den, cc );
     545            mpz_add( n, _num, n );
    531546          }
    532547        }
     
    535550    {
    536551        ASSERT( c->levelcoeff() == IntegerDomain, "expected integer" );
    537         mpz_init( &n );
    538         mpz_mul( &n, &_den, &InternalInteger::MPI( c ) );
    539         mpz_add( &n, &_num, &n );
    540     }
    541     mpz_init_set( &d, &_den );
     552        mpz_init( n );
     553        mpz_mul( n, _den, InternalInteger::MPI( c ) );
     554        mpz_add( n, _num, n );
     555    }
     556    mpz_init_set( d, _den );
    542557    // at this point there is no way that the result is not a true rational
    543558    if ( deleteObject() ) delete this;
     
    548563{
    549564    ASSERT( ::is_imm( c ) == INTMARK || ! ::is_imm( c ), "expected integer" );
    550     MP_INT n, d;
     565    mpz_t n, d;
    551566    if ( ::is_imm( c ) )
    552567    {
     
    558573                if ( getRefCount() == 1 )
    559574                {
    560                     mpz_neg( &_num, &_num );
     575                    mpz_neg( _num, _num );
    561576                    return this;
    562577                }
     
    564579                {
    565580                    decRefCount();
    566                     mpz_init_set( &d, &_den );
    567                     mpz_init_set( &n, &_num );
    568                     mpz_neg( &n, &n );
     581                    mpz_init_set( d, _den );
     582                    mpz_init_set( n, _num );
     583                    mpz_neg( n, n );
    569584                    return new InternalRational( n, d );
    570585                }
     
    573588                return this;
    574589        }
    575         mpz_init( &n );
     590        mpz_init( n );
    576591        if ( cc < 0 )
    577592        {
    578             mpz_mul_ui( &n, &_den, -cc );
    579             mpz_neg( &n, &n );
    580         }
    581         else
    582             mpz_mul_ui( &n, &_den, cc );
     593            mpz_mul_ui( n, _den, -cc );
     594            mpz_neg( n, n );
     595        }
     596        else
     597            mpz_mul_ui( n, _den, cc );
    583598        if ( negate )
    584             mpz_sub( &n, &n, &_num );
    585         else
    586             mpz_sub( &n, &_num, &n );
     599            mpz_sub( n, n, _num );
     600        else
     601            mpz_sub( n, _num, n );
    587602    }
    588603    else
    589604    {
    590605        ASSERT( c->levelcoeff() == IntegerDomain, "expected integer" );
    591         mpz_init( &n );
    592         mpz_mul( &n, &_den, &InternalInteger::MPI( c ) );
     606        mpz_init( n );
     607        mpz_mul( n, _den, InternalInteger::MPI( c ) );
    593608        if ( negate )
    594             mpz_sub( &n, &n, &_num );
    595         else
    596             mpz_sub( &n, &_num, &n );
    597     }
    598     mpz_init_set( &d, &_den );
     609            mpz_sub( n, n, _num );
     610        else
     611            mpz_sub( n, _num, n );
     612    }
     613    mpz_init_set( d, _den );
    599614    // at this point there is no way that the result is not a true rational
    600615    if ( deleteObject() ) delete this;
     
    605620{
    606621    ASSERT( ::is_imm( c ) == INTMARK || ! ::is_imm( c ), "expected integer" );
    607     MP_INT n, d, g;
     622    mpz_t n, d, g;
    608623    if ( ::is_imm( c ) )
    609624    {
     
    614629            return CFFactory::basic( 0 );
    615630        }
    616         mpz_init_set_si( &n, cc );
     631        mpz_init_set_si( n, cc );
    617632    }
    618633    else
    619634    {
    620635        ASSERT( c->levelcoeff() == IntegerDomain, "expected integer" );
    621         mpz_init_set( &n, &InternalInteger::MPI( c ) );
    622     }
    623     mpz_init( &g );
    624     mpz_gcd( &g, &n, &_den );
    625     if ( mpz_cmp_si( &g, 1 ) == 0 )
    626     {
    627         mpz_mul( &n, &n, &_num );
    628         mpz_init_set( &d, &_den );
    629     }
    630     else
    631     {
    632         mpz_divexact( &n, &n, &g );
    633         mpz_mul( &n, &n, &_num );
    634         mpz_init( &d );
    635         mpz_divexact( &d, &_den, &g );
    636     }
    637     mpz_clear( &g );
     636        mpz_init_set( n, InternalInteger::MPI( c ) );
     637    }
     638    mpz_init( g );
     639    mpz_gcd( g, n, _den );
     640    if ( mpz_cmp_si( g, 1 ) == 0 )
     641    {
     642        mpz_mul( n, n, _num );
     643        mpz_init_set( d, _den );
     644    }
     645    else
     646    {
     647        mpz_divexact( n, n, g );
     648        mpz_mul( n, n, _num );
     649        mpz_init( d );
     650        mpz_divexact( d, _den, g );
     651    }
     652    mpz_clear( g );
    638653    if ( deleteObject() ) delete this;
    639     if ( mpz_cmp_si( &d, 1 ) == 0 )
    640     {
    641         mpz_clear( &d );
    642         if ( mpz_is_imm( &n ) )
    643         {
    644             InternalCF * res = int2imm( mpz_get_si( &n ) );
    645             mpz_clear( &n );
     654    if ( mpz_cmp_si( d, 1 ) == 0 )
     655    {
     656        mpz_clear( d );
     657        if ( mpz_is_imm( n ) )
     658        {
     659            InternalCF * res = int2imm( mpz_get_si( n ) );
     660            mpz_clear( n );
    646661            return res;
    647662        }
     
    658673{
    659674    ASSERT( ::is_imm( c ) == INTMARK || ! ::is_imm( c ), "expected integer" );
    660     MP_INT n, d, g;
     675    mpz_t n, d, g;
    661676    if ( ::is_imm( c ) )
    662677    {
     
    671686        if ( invert )
    672687        {
    673             mpz_init_set_si( &n, cc );
    674             mpz_mul( &n, &n, &_den );
    675             mpz_init_set( &d, &_num );
    676         }
    677         else
    678         {
    679             mpz_init_set_si( &d, cc );
    680             mpz_mul( &d, &d, &_den );
    681             mpz_init_set( &n, &_num );
     688            mpz_init_set_si( n, cc );
     689            mpz_mul( n, n, _den );
     690            mpz_init_set( d, _num );
     691        }
     692        else
     693        {
     694            mpz_init_set_si( d, cc );
     695            mpz_mul( d, d, _den );
     696            mpz_init_set( n, _num );
    682697        }
    683698    }
     
    687702        if ( invert )
    688703        {
    689             mpz_init_set( &n, &InternalInteger::MPI( c ) );
    690             mpz_mul( &n, &n, &_den );
    691             mpz_init_set( &d, &_num );
    692         }
    693         else
    694         {
    695             mpz_init_set( &d, &InternalInteger::MPI( c ) );
    696             mpz_mul( &d, &d, &_den );
    697             mpz_init_set( &n, &_num );
    698         }
    699     }
    700     if ( mpz_cmp_si( &d, 0 ) < 0 )
    701     {
    702         mpz_neg( &d, &d );
    703         mpz_neg( &n, &n );
    704     }
    705     mpz_init( &g );
    706     mpz_gcd( &g, &n, &d );
    707     if ( mpz_cmp_si( &g, 1 ) != 0 )
    708     {
    709         mpz_divexact( &d, &d, &g );
    710         mpz_divexact( &n, &n, &g );
    711     }
    712     mpz_clear( &g );
     704            mpz_init_set( n, InternalInteger::MPI( c ) );
     705            mpz_mul( n, n, _den );
     706            mpz_init_set( d, _num );
     707        }
     708        else
     709        {
     710            mpz_init_set( d, InternalInteger::MPI( c ) );
     711            mpz_mul( d, d, _den );
     712            mpz_init_set( n, _num );
     713        }
     714    }
     715    if ( mpz_cmp_si( d, 0 ) < 0 )
     716    {
     717        mpz_neg( d, d );
     718        mpz_neg( n, n );
     719    }
     720    mpz_init( g );
     721    mpz_gcd( g, n, d );
     722    if ( mpz_cmp_si( g, 1 ) != 0 )
     723    {
     724        mpz_divexact( d, d, g );
     725        mpz_divexact( n, n, g );
     726    }
     727    mpz_clear( g );
    713728    if ( deleteObject() ) delete this;
    714729    if ( ! invert )
     
    717732        return new InternalRational( n, d );
    718733    }
    719     if ( mpz_cmp_si( &d, 1 ) == 0 )
    720     {
    721         mpz_clear( &d );
    722         if ( mpz_is_imm( &n ) )
    723         {
    724             InternalCF * res = int2imm( mpz_get_si( &n ) );
    725             mpz_clear( &n );
     734    if ( mpz_cmp_si( d, 1 ) == 0 )
     735    {
     736        mpz_clear( d );
     737        if ( mpz_is_imm( n ) )
     738        {
     739            InternalCF * res = int2imm( mpz_get_si( n ) );
     740            mpz_clear( n );
    726741            return res;
    727742        }
     
    801816{
    802817    ASSERT( getRefCount() == 1, "illegal operation" );
    803     MP_INT g;
    804     mpz_init( &g );
    805     mpz_gcd( &g, &_num, &_den );
    806     if ( mpz_cmp_si( &g, 1 ) != 0 )
    807     {
    808         mpz_divexact( &_num, &_num, &g );
    809         mpz_divexact( &_den, &_den, &g );
     818    mpz_t g;
     819    mpz_init( g );
     820    mpz_gcd( g, _num, _den );
     821    if ( mpz_cmp_si( g, 1 ) != 0 )
     822    {
     823        mpz_divexact( _num, _num, g );
     824        mpz_divexact( _den, _den, g );
    810825    }
    811826    // Hier brauchen wir ein mpz_clear, J.M.
    812     mpz_clear( &g );
    813     if ( mpz_cmp_si( &_den, 0 ) < 0 )
    814     {
    815         mpz_neg( &_num, &_num );
    816         mpz_neg( &_den, &_den );
    817     }
    818     if ( mpz_cmp_si( &_den, 1 ) == 0 )
    819     {
    820         if ( mpz_is_imm( &_num ) )
    821         {
    822             InternalCF * res = int2imm( mpz_get_si( &_num ) );
     827    mpz_clear( g );
     828    if ( mpz_cmp_si( _den, 0 ) < 0 )
     829    {
     830        mpz_neg( _num, _num );
     831        mpz_neg( _den, _den );
     832    }
     833    if ( mpz_cmp_si( _den, 1 ) == 0 )
     834    {
     835        if ( mpz_is_imm( _num ) )
     836        {
     837            InternalCF * res = int2imm( mpz_get_si( _num ) );
    823838            delete this;
    824839            return res;
     
    826841        else
    827842        {
    828             MP_INT res;
    829             mpz_init_set( &res, &_num );
     843            mpz_t res;
     844            mpz_init_set( res, _num );
    830845            delete this;
    831846            return new InternalInteger( res );
     
    839854int InternalRational::intval() const
    840855{
    841     ASSERT( mpz_cmp_si( &_den, 1 ) == 0, "illegal operation" );
    842     return (int)mpz_get_si( &_num );
     856    ASSERT( mpz_cmp_si( _den, 1 ) == 0, "illegal operation" );
     857    return (int)mpz_get_si( _num );
    843858}
    844859
     
    848863InternalRational::sign () const
    849864{
    850     return mpz_sgn( &_num );
     865    return mpz_sgn( _num );
    851866}
    852867//}}}
  • factory/int_rat.h

    r1c48503 ra52291  
    2727{
    2828private:
    29     MP_INT _num;
    30     MP_INT _den;
     29    mpz_t _num;
     30    mpz_t _den;
    3131    static int initialized;
    32     static MP_INT & MPQNUM( const InternalCF * const c );
    33     static MP_INT & MPQDEN( const InternalCF * const c );
    34     static void normalize( const MP_INT &, const MP_INT &, MP_INT &, MP_INT & );
     32    static mpz_ptr MPQNUM( const InternalCF * const c );
     33    static mpz_ptr MPQDEN( const InternalCF * const c );
     34    static void normalize( const mpz_ptr, const mpz_ptr, mpz_ptr, mpz_ptr );
    3535public:
    3636    InternalRational();
     
    4242    InternalRational( const int n, const int d );
    4343    InternalRational( const char * str );
    44     InternalRational( const MP_INT & );
    45     InternalRational( const MP_INT &, const MP_INT & );
     44    InternalRational( const mpz_ptr );
     45    InternalRational( const mpz_ptr , const mpz_ptr );
    4646    ~InternalRational();
    4747    InternalCF* deepCopyObject() const;
     
    100100    friend void gmp_numerator ( const CanonicalForm & f, mpz_ptr result );
    101101    friend void gmp_denominator ( const CanonicalForm & f, mpz_ptr result );
    102     friend CanonicalForm make_cf ( const MP_INT & n, const MP_INT & d );
     102    friend CanonicalForm make_cf ( const mpz_ptr n, const mpz_ptr d );
    103103};
    104104
    105 inline MP_INT & InternalRational::MPQNUM( const InternalCF * const c )
     105inline mpz_ptr InternalRational::MPQNUM( const InternalCF * const c )
    106106{
    107107    return (((InternalRational*)c)->_num);
    108108}
    109109
    110 inline MP_INT & InternalRational::MPQDEN( const InternalCF * const c )
     110inline mpz_ptr InternalRational::MPQDEN( const InternalCF * const c )
    111111{
    112112    return (((InternalRational*)c)->_den);
  • factory/singext.cc

    r1c48503 ra52291  
    2323    if ( ff->levelcoeff() == IntegerDomain )
    2424    {
    25         mpz_init_set( result, &(InternalInteger::MPI( ff )) );
     25        mpz_init_set( result, (InternalInteger::MPI( ff )) );
    2626        ff->deleteObject();
    2727    }
    2828    else  if ( ff->levelcoeff() == RationalDomain )
    2929    {
    30         mpz_init_set( result, &(InternalRational::MPQNUM( ff )) );
     30        mpz_init_set( result, (InternalRational::MPQNUM( ff )) );
    3131        ff->deleteObject();
    3232    }
     
    4848    else  if ( ff->levelcoeff() == RationalDomain )
    4949    {
    50         mpz_init_set( result, &(InternalRational::MPQDEN( ff )) );
     50        mpz_init_set( result, (InternalRational::MPQDEN( ff )) );
    5151        ff->deleteObject();
    5252    }
     
    6464
    6565CanonicalForm
    66 make_cf ( const MP_INT & n )
     66make_cf ( const mpz_ptr n )
    6767{
    6868    return CanonicalForm( CFFactory::basic( n ) );
     
    7070
    7171CanonicalForm
    72 make_cf ( const MP_INT & n, const MP_INT & d, bool normalize )
     72make_cf ( const mpz_ptr n, const mpz_ptr d, bool normalize )
    7373{
    7474    return CanonicalForm( CFFactory::rational( n, d, normalize ) );
  • factory/singext.h

    r1c48503 ra52291  
    1818int gf_value (const CanonicalForm & f );
    1919
    20 CanonicalForm make_cf ( const MP_INT & n );
     20CanonicalForm make_cf ( const mpz_ptr n );
    2121
    22 CanonicalForm make_cf ( const MP_INT & n, const MP_INT & d, bool normalize );
     22CanonicalForm make_cf ( const mpz_ptr n, const mpz_ptr d, bool normalize );
    2323
    2424CanonicalForm make_cf_from_gf ( const int z );
  • factory/winnt/factory.h

    r1c48503 ra52291  
    971971
    972972
    973 MP_INT gmp_numerator ( const CanonicalForm & f );
    974 
    975 MP_INT gmp_denominator ( const CanonicalForm & f );
     973mpz_ptr gmp_numerator ( const CanonicalForm & f );
     974
     975mpz_ptr gmp_denominator ( const CanonicalForm & f );
    976976
    977977int gf_value (const CanonicalForm & f );
    978978
    979 CanonicalForm make_cf ( const MP_INT & n );
    980 
    981 CanonicalForm make_cf ( const MP_INT & n, const MP_INT & d, bool normalize );
     979CanonicalForm make_cf ( const mpz_ptr n );
     980
     981CanonicalForm make_cf ( const mpz_ptr n, const mpz_ptr d, bool normalize );
    982982
    983983CanonicalForm make_cf_from_gf ( const int z );
Note: See TracChangeset for help on using the changeset viewer.