Changeset a52291 in git for factory/int_int.cc


Ignore:
Timestamp:
Nov 24, 2011, 2:35:53 PM (12 years ago)
Author:
Martin Lee <martinlee84@…>
Branches:
(u'spielwiese', '0d6b7fcd9813a1ca1ed4220cfa2b104b97a0a003')
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
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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//}}}
Note: See TracChangeset for help on using the changeset viewer.