Changeset a52291 in git for factory/int_pp.cc


Ignore:
Timestamp:
Nov 24, 2011, 2:35:53 PM (12 years ago)
Author:
Martin Lee <martinlee84@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
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_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//}}}
Note: See TracChangeset for help on using the changeset viewer.