Changeset a52291 in git for factory/int_int.cc
- Timestamp:
- Nov 24, 2011, 2:35:53 PM (12 years ago)
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
factory/int_int.cc
r1c48503 ra52291 17 17 InternalInteger::InternalInteger() 18 18 { 19 mpz_init( &thempi );19 mpz_init( thempi ); 20 20 } 21 21 22 22 InternalInteger::InternalInteger( const int i ) 23 23 { 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 27 InternalInteger::InternalInteger( const mpz_ptr mpi) { thempi[0]=*mpi;} 28 28 29 29 InternalInteger::InternalInteger( const char * str, const int base ) 30 30 { 31 mpz_init_set_str( &thempi, str, base );31 mpz_init_set_str( thempi, str, base ); 32 32 } 33 33 34 34 InternalInteger::~InternalInteger() 35 35 { 36 mpz_clear( &thempi );36 mpz_clear( thempi ); 37 37 } 38 38 … … 40 40 { 41 41 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 ); 44 44 } 45 45 … … 47 47 void InternalInteger::print( OSTREAM & os, char * c ) 48 48 { 49 if ( *c == '*' && mpz_cmp_si( &thempi, 1 ) == 0 )49 if ( *c == '*' && mpz_cmp_si( thempi, 1 ) == 0 ) 50 50 os << c+1; 51 else if ( *c == '*' && mpz_cmp_si( &thempi, -1 ) == 0 )51 else if ( *c == '*' && mpz_cmp_si( thempi, -1 ) == 0 ) 52 52 os << '-' << c+1; 53 53 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 ); 56 56 os << str << c; 57 57 delete [] str; … … 62 62 bool InternalInteger::is_imm() const 63 63 { 64 return mpz_is_imm( &thempi );64 return mpz_is_imm( thempi ); 65 65 } 66 66 … … 90 90 decRefCount(); 91 91 mpz_t dummy; 92 mpz_init_set( dummy, &thempi );92 mpz_init_set( dummy, thempi ); 93 93 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 ); 99 99 return this; 100 100 } … … 110 110 mpz_t dummy; 111 111 mpz_init( dummy ); 112 mpz_add( dummy, &thempi, &MPI( c ) );112 mpz_add( dummy, thempi, MPI( c ) ); 113 113 if ( mpz_is_imm( dummy ) ) 114 114 { … … 118 118 } 119 119 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 ) ); 128 128 delete this; 129 129 return res; … … 141 141 mpz_t dummy; 142 142 mpz_init( dummy ); 143 mpz_sub( dummy, &thempi, &MPI( c ) );143 mpz_sub( dummy, thempi, MPI( c ) ); 144 144 if ( mpz_is_imm( dummy ) ) 145 145 { … … 149 149 } 150 150 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 ) ); 159 159 delete this; 160 160 return res; … … 172 172 mpz_t dummy; 173 173 mpz_init( dummy ); 174 mpz_mul( dummy, &thempi, &MPI( c ) );174 mpz_mul( dummy, thempi, MPI( c ) ); 175 175 #if 0 176 176 if ( mpz_is_imm( dummy ) ) … … 183 183 else 184 184 #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 ) ); 190 190 #if 0 191 191 if ( mpz_is_imm( &thempi ) ) … … 208 208 { 209 209 ASSERT( ! ::is_imm( c ) && c->levelcoeff() == IntegerDomain, "incompatible base coefficients" ); 210 return mpz_cmp( &thempi, &MPI( c ) );210 return mpz_cmp( thempi, MPI( c ) ); 211 211 } 212 212 … … 215 215 { 216 216 ASSERT( ::is_imm( c ) == INTMARK, "incompatible base coefficients" ); 217 return mpz_cmp_si( &thempi, imm2int( c ) );217 return mpz_cmp_si( thempi, imm2int( c ) ); 218 218 } 219 219 //}}} … … 229 229 mpz_init( dummy ); 230 230 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 ); 234 234 if ( mpz_is_imm( dummy ) ) 235 235 { … … 239 239 } 240 240 else 241 return new InternalInteger( dummy [0]);241 return new InternalInteger( dummy ); 242 242 } 243 243 else 244 244 { 245 245 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 ) ); 252 252 delete this; 253 253 return res; … … 269 269 { 270 270 mpz_init_set_si( dummy, cc ); 271 mpz_sub( dummy, dummy, &thempi );271 mpz_sub( dummy, dummy, thempi ); 272 272 } 273 273 else … … 275 275 mpz_init( dummy ); 276 276 if ( cc < 0 ) 277 mpz_add_ui( dummy, &thempi, -cc );277 mpz_add_ui( dummy, thempi, -cc ); 278 278 else 279 mpz_sub_ui( dummy, &thempi, cc );279 mpz_sub_ui( dummy, thempi, cc ); 280 280 } 281 281 if ( mpz_is_imm( dummy ) ) … … 286 286 } 287 287 else 288 return new InternalInteger( dummy [0]);288 return new InternalInteger( dummy ); 289 289 } 290 290 else … … 294 294 mpz_t dummy; 295 295 mpz_init_set_si( dummy, cc ); 296 mpz_sub( &thempi, dummy, &thempi );296 mpz_sub( thempi, dummy, thempi ); 297 297 mpz_clear( dummy ); 298 298 } 299 299 else 300 300 if ( cc < 0 ) 301 mpz_add_ui( &thempi, &thempi, -cc );301 mpz_add_ui( thempi, thempi, -cc ); 302 302 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 ) ); 307 307 delete this; 308 308 return res; … … 324 324 if ( cc < 0 ) 325 325 { 326 mpz_mul_ui( dummy, &thempi, -cc );326 mpz_mul_ui( dummy, thempi, -cc ); 327 327 mpz_neg( dummy, dummy ); 328 328 } 329 329 else 330 mpz_mul_ui( dummy, &thempi, cc );330 mpz_mul_ui( dummy, thempi, cc ); 331 331 if ( mpz_is_imm( dummy ) ) 332 332 { … … 336 336 } 337 337 else 338 return new InternalInteger( dummy [0]);338 return new InternalInteger( dummy ); 339 339 } 340 340 else … … 342 342 if ( cc < 0 ) 343 343 { 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 ) ); 352 352 delete this; 353 353 return res; … … 372 372 mpz_t result; 373 373 mpz_init( result ); 374 mpz_gcd( result, &thempi, &MPI( c ) );374 mpz_gcd( result, thempi, MPI( c ) ); 375 375 mpz_abs( result, result ); 376 376 … … 383 383 } 384 384 else 385 return new InternalInteger( result [0]);385 return new InternalInteger( result ); 386 386 } 387 387 … … 409 409 mpz_init( dummy ); 410 410 // 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 ); 412 412 mpz_clear( dummy ); 413 413 if ( cInt < 0 ) cInt = -cInt; … … 434 434 mpz_init( aMPI ); 435 435 mpz_init( bMPI ); 436 mpz_gcdext( result, aMPI, bMPI, &thempi, &MPI( c ) );436 mpz_gcdext( result, aMPI, bMPI, thempi, MPI( c ) ); 437 437 438 438 // check and modify signs … … 451 451 } 452 452 else 453 a = CanonicalForm( new InternalInteger( aMPI [0]) );453 a = CanonicalForm( new InternalInteger( aMPI ) ); 454 454 if ( mpz_is_imm( bMPI ) ) 455 455 { … … 458 458 } 459 459 else 460 b = CanonicalForm( new InternalInteger( bMPI [0]) );460 b = CanonicalForm( new InternalInteger( bMPI ) ); 461 461 if ( mpz_is_imm( result ) ) 462 462 { … … 466 466 } 467 467 else 468 return new InternalInteger( result [0]);468 return new InternalInteger( result ); 469 469 } 470 470 … … 515 515 int InternalInteger::intval() const 516 516 { 517 return (int)mpz_get_si( &thempi );517 return (int)mpz_get_si( thempi ); 518 518 } 519 519 520 520 int InternalInteger::intmod( int p ) const 521 521 { 522 return (int)mpz_fdiv_ui( &thempi, (unsigned long)p );522 return (int)mpz_fdiv_ui( thempi, (unsigned long)p ); 523 523 } 524 524 … … 528 528 InternalInteger::sign () const 529 529 { 530 return mpz_sgn( &thempi );530 return mpz_sgn( thempi ); 531 531 } 532 532 //}}} … … 537 537 InternalInteger::sqrt () 538 538 { 539 ASSERT( mpz_cmp_si( &thempi, 0 ) >= 0, "sqrt() argument < 0" );539 ASSERT( mpz_cmp_si( thempi, 0 ) >= 0, "sqrt() argument < 0" ); 540 540 mpz_t result; 541 541 mpz_init( result ); 542 mpz_sqrt( result, &thempi );542 mpz_sqrt( result, thempi ); 543 543 if ( mpz_is_imm( result ) ) 544 544 { … … 548 548 } 549 549 else 550 return new InternalInteger( result [0]);550 return new InternalInteger( result ); 551 551 } 552 552 //}}} … … 557 557 InternalInteger::ilog2 () 558 558 { 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.