Changeset a52291 in git for factory/int_pp.cc
- Timestamp:
- Nov 24, 2011, 2:35:53 PM (12 years ago)
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
factory/int_pp.cc
r1c48503 ra52291 12 12 #include "imm.h" 13 13 14 MP_INTInternalPrimePower::primepow;15 MP_INTInternalPrimePower::primepowhalf;14 mpz_t InternalPrimePower::primepow; 15 mpz_t InternalPrimePower::primepowhalf; 16 16 int InternalPrimePower::prime; 17 17 int InternalPrimePower::exp; … … 21 21 InternalPrimePower::InternalPrimePower() 22 22 { 23 mpz_init( &thempi );23 mpz_init( thempi ); 24 24 } 25 25 26 26 InternalPrimePower::InternalPrimePower( const int i ) 27 27 { 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 ); 33 33 } 34 34 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 38 InternalPrimePower::InternalPrimePower( const mpz_ptr mpi) { thempi[0]=*mpi;} 39 39 40 40 InternalPrimePower::InternalPrimePower( const char * str, const int base ) 41 41 { 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 ); 47 47 } 48 48 else 49 mpz_mod( &thempi, &thempi, &primepow );49 mpz_mod( thempi, thempi, primepow ); 50 50 } 51 51 52 52 InternalPrimePower::~InternalPrimePower() 53 53 { 54 mpz_clear( &thempi );54 mpz_clear( thempi ); 55 55 } 56 56 57 57 InternalCF* InternalPrimePower::deepCopyObject() const 58 58 { 59 MP_INTdummy;60 mpz_init_set( &dummy, &thempi );59 mpz_t dummy; 60 mpz_init_set( dummy, thempi ); 61 61 return new InternalPrimePower( dummy ); 62 62 } … … 65 65 { 66 66 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 ); 71 71 } 72 72 else 73 mpz_mod( &thempi, &thempi, &primepow );73 mpz_mod( thempi, thempi, primepow ); 74 74 return this; 75 75 } … … 77 77 int InternalPrimePower::initialize() 78 78 { 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 ); 81 81 prime = 3; 82 82 exp = 1; … … 89 89 ASSERT( p > 1 && k > 0, "illegal prime power" ); 90 90 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 ); 94 94 prime = p; 95 95 exp = k; … … 112 112 void InternalPrimePower::print( OSTREAM & os, char * c ) 113 113 { 114 if ( *c == '*' && mpz_cmp_si( &thempi, 1 ) == 0 )114 if ( *c == '*' && mpz_cmp_si( thempi, 1 ) == 0 ) 115 115 os << c+1; 116 else if ( *c == '*' && mpz_cmp_si( &thempi, -1 ) == 0 )116 else if ( *c == '*' && mpz_cmp_si( thempi, -1 ) == 0 ) 117 117 os << '-' << c+1; 118 118 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 ); 121 121 os << str << c; 122 122 delete [] str; … … 130 130 InternalPrimePower::isOne () const 131 131 { 132 return mpz_cmp_ui( &thempi, 1 ) == 0;132 return mpz_cmp_ui( thempi, 1 ) == 0; 133 133 } 134 134 … … 136 136 InternalPrimePower::isZero () const 137 137 { 138 return mpz_sgn( &thempi ) == 0;138 return mpz_sgn( thempi ) == 0; 139 139 } 140 140 //}}} … … 168 168 if ( getRefCount() > 1 ) { 169 169 decRefCount(); 170 MP_INTdummy;171 mpz_init( &dummy );172 mpz_sub( &dummy, &primepow, &thempi );170 mpz_t dummy; 171 mpz_init( dummy ); 172 mpz_sub( dummy, primepow, thempi ); 173 173 return new InternalPrimePower( dummy ); 174 174 } else { 175 mpz_sub( &thempi, &primepow, &thempi );175 mpz_sub( thempi, primepow, thempi ); 176 176 return this; 177 177 } … … 184 184 if ( getRefCount() > 1 ) { 185 185 decRefCount(); 186 MP_INTdummy;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 ); 191 191 return new InternalPrimePower( dummy ); 192 192 } 193 193 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 ); 197 197 return this; 198 198 } … … 203 203 if ( getRefCount() > 1 ) { 204 204 decRefCount(); 205 MP_INTdummy;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 ); 210 210 return new InternalPrimePower( dummy ); 211 211 } 212 212 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 ); 216 216 return this; 217 217 } … … 222 222 if ( getRefCount() > 1 ) { 223 223 decRefCount(); 224 MP_INTdummy;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 ); 228 228 return new InternalPrimePower( dummy ); 229 229 } 230 230 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 ); 233 233 return this; 234 234 } … … 248 248 if ( getRefCount() > 1 ) { 249 249 decRefCount(); 250 MP_INTdummy, 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 ); 259 259 return new InternalPrimePower( b ); 260 260 } 261 261 else { 262 MP_INTdummy, 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 ); 271 271 return this; 272 272 } … … 295 295 } 296 296 else { 297 MP_INTdummy, 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 ); 306 306 quot = new InternalPrimePower( b ); 307 307 rem = CFFactory::basic( 0 ); … … 322 322 { 323 323 ASSERT( ! ::is_imm( c ) && c->levelcoeff() == PrimePowerDomain, "incompatible base coefficients" ); 324 return mpz_cmp( &thempi, &MPI( c ) );324 return mpz_cmp( thempi, MPI( c ) ); 325 325 } 326 326 … … 398 398 InternalPrimePower::intval () const 399 399 { 400 return (int)mpz_get_si( &thempi );400 return (int)mpz_get_si( thempi ); 401 401 } 402 402 … … 404 404 InternalPrimePower::intmod( int p ) const 405 405 { 406 return (int)mpz_fdiv_ui( &thempi, (unsigned long)p );406 return (int)mpz_fdiv_ui( thempi, (unsigned long)p ); 407 407 } 408 408 … … 412 412 InternalPrimePower::sign () const 413 413 { 414 return mpz_sgn( &thempi );414 return mpz_sgn( thempi ); 415 415 } 416 416 //}}}
Note: See TracChangeset
for help on using the changeset viewer.