Changeset 186402 in git
- Timestamp:
- Apr 16, 2010, 7:17:39 PM (13 years ago)
- Branches:
- (u'spielwiese', '8d54773d6c9e2f1d2593a28bc68b7eeab54ed529')
- Children:
- 5a940505f2e29bfbe6377eb931873ce2abac9b81
- Parents:
- fd08e70fe42432d089c746dc88bf583885a68e43
- Location:
- factory
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
factory/int_int.cc
rfd08e7 r186402 39 39 InternalCF* InternalInteger::deepCopyObject() const 40 40 { 41 MP_INTdummy;42 mpz_init_set( &dummy, &thempi );43 return new InternalInteger( dummy );41 mpz_t dummy; 42 mpz_init_set( dummy, &thempi ); 43 return new InternalInteger( dummy[0] ); 44 44 } 45 45 … … 89 89 { 90 90 decRefCount(); 91 MP_INTdummy;92 mpz_init_set( &dummy, &thempi );93 mpz_neg( &dummy, &dummy );94 return new InternalInteger( dummy );91 mpz_t dummy; 92 mpz_init_set( dummy, &thempi ); 93 mpz_neg( dummy, dummy ); 94 return new InternalInteger( dummy[0] ); 95 95 } 96 96 else … … 108 108 { 109 109 decRefCount(); 110 MP_INTdummy;111 mpz_init( &dummy );112 mpz_add( &dummy, &thempi, &MPI( c ) );113 if ( mpz_is_imm( &dummy ) )114 { 115 InternalCF * res = int2imm( mpz_get_si( &dummy ) );116 mpz_clear( &dummy );117 return res; 118 } 119 else 120 return new InternalInteger( dummy );110 mpz_t dummy; 111 mpz_init( dummy ); 112 mpz_add( dummy, &thempi, &MPI( c ) ); 113 if ( mpz_is_imm( dummy ) ) 114 { 115 InternalCF * res = int2imm( mpz_get_si( dummy ) ); 116 mpz_clear( dummy ); 117 return res; 118 } 119 else 120 return new InternalInteger( dummy[0] ); 121 121 } 122 122 else … … 139 139 { 140 140 decRefCount(); 141 MP_INTdummy;142 mpz_init( &dummy );143 mpz_sub( &dummy, &thempi, &MPI( c ) );144 if ( mpz_is_imm( &dummy ) )145 { 146 InternalCF * res = int2imm( mpz_get_si( &dummy ) );147 mpz_clear( &dummy );148 return res; 149 } 150 else 151 return new InternalInteger( dummy );141 mpz_t dummy; 142 mpz_init( dummy ); 143 mpz_sub( dummy, &thempi, &MPI( c ) ); 144 if ( mpz_is_imm( dummy ) ) 145 { 146 InternalCF * res = int2imm( mpz_get_si( dummy ) ); 147 mpz_clear( dummy ); 148 return res; 149 } 150 else 151 return new InternalInteger( dummy[0] ); 152 152 } 153 153 else … … 170 170 { 171 171 decRefCount(); 172 MP_INTdummy;173 mpz_init( &dummy );174 mpz_mul( &dummy, &thempi, &MPI( c ) );172 mpz_t dummy; 173 mpz_init( dummy ); 174 mpz_mul( dummy, &thempi, &MPI( c ) ); 175 175 #if 0 176 if ( mpz_is_imm( &dummy ) )176 if ( mpz_is_imm( dummy ) ) 177 177 { 178 178 // can this happen ??? 179 InternalCF * res = int2imm( mpz_get_si( &dummy ) );180 mpz_clear( &dummy );179 InternalCF * res = int2imm( mpz_get_si( dummy ) ); 180 mpz_clear( dummy ); 181 181 return res; 182 182 } 183 183 else 184 184 #endif 185 return new InternalInteger( dummy );185 return new InternalInteger( dummy[0] ); 186 186 } 187 187 else … … 226 226 { 227 227 decRefCount(); 228 MP_INTdummy;229 mpz_init( &dummy );228 mpz_t dummy; 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 ); 234 if ( mpz_is_imm( &dummy ) ) 235 { 236 InternalCF * res = int2imm( mpz_get_si( &dummy ) ); 237 mpz_clear( &dummy ); 238 return res; 239 } 240 else 241 return new InternalInteger( dummy ); 242 } 243 else { 231 mpz_sub_ui( dummy, &thempi, -cc ); 232 else 233 mpz_add_ui( dummy, &thempi, cc ); 234 if ( mpz_is_imm( dummy ) ) 235 { 236 InternalCF * res = int2imm( mpz_get_si( dummy ) ); 237 mpz_clear( dummy ); 238 return res; 239 } 240 else 241 return new InternalInteger( dummy[0] ); 242 } 243 else 244 { 244 245 if ( cc < 0 ) 245 246 mpz_sub_ui( &thempi, &thempi, -cc ); … … 264 265 { 265 266 decRefCount(); 266 MP_INTdummy;267 mpz_t dummy; 267 268 if ( negate ) 268 269 { 269 mpz_init_set_si( &dummy, cc );270 mpz_sub( &dummy, &dummy, &thempi );271 } 272 else 273 { 274 mpz_init( &dummy );270 mpz_init_set_si( dummy, cc ); 271 mpz_sub( dummy, dummy, &thempi ); 272 } 273 else 274 { 275 mpz_init( dummy ); 275 276 if ( cc < 0 ) 276 mpz_add_ui( &dummy, &thempi, -cc );277 mpz_add_ui( dummy, &thempi, -cc ); 277 278 else 278 mpz_sub_ui( &dummy, &thempi, cc );279 } 280 if ( mpz_is_imm( &dummy ) )281 { 282 InternalCF * res = int2imm( mpz_get_si( &dummy ) );283 mpz_clear( &dummy );284 return res; 285 } 286 else 287 return new InternalInteger( dummy );279 mpz_sub_ui( dummy, &thempi, cc ); 280 } 281 if ( mpz_is_imm( dummy ) ) 282 { 283 InternalCF * res = int2imm( mpz_get_si( dummy ) ); 284 mpz_clear( dummy ); 285 return res; 286 } 287 else 288 return new InternalInteger( dummy[0] ); 288 289 } 289 290 else … … 291 292 if ( negate ) 292 293 { 293 MP_INTdummy;294 mpz_init_set_si( &dummy, cc );295 mpz_sub( &thempi, &dummy, &thempi );296 mpz_clear( &dummy );294 mpz_t dummy; 295 mpz_init_set_si( dummy, cc ); 296 mpz_sub( &thempi, dummy, &thempi ); 297 mpz_clear( dummy ); 297 298 } 298 299 else … … 319 320 { 320 321 decRefCount(); 321 MP_INTdummy;322 mpz_init( &dummy );322 mpz_t dummy; 323 mpz_init( dummy ); 323 324 if ( cc < 0 ) 324 325 { 325 mpz_mul_ui( &dummy, &thempi, -cc );326 mpz_neg( &dummy, &dummy );327 } 328 else 329 mpz_mul_ui( &dummy, &thempi, cc );330 if ( mpz_is_imm( &dummy ) )331 { 332 InternalCF * res = int2imm( mpz_get_si( &dummy ) );333 mpz_clear( &dummy );334 return res; 335 } 336 else 337 return new InternalInteger( dummy );326 mpz_mul_ui( dummy, &thempi, -cc ); 327 mpz_neg( dummy, dummy ); 328 } 329 else 330 mpz_mul_ui( dummy, &thempi, cc ); 331 if ( mpz_is_imm( dummy ) ) 332 { 333 InternalCF * res = int2imm( mpz_get_si( dummy ) ); 334 mpz_clear( dummy ); 335 return res; 336 } 337 else 338 return new InternalInteger( dummy[0] ); 338 339 } 339 340 else … … 369 370 370 371 // calculate gcd 371 MP_INTresult;372 mpz_init( &result );373 mpz_gcd( &result, &thempi, &MPI( c ) );374 mpz_abs( &result, &result );372 mpz_t result; 373 mpz_init( result ); 374 mpz_gcd( result, &thempi, &MPI( c ) ); 375 mpz_abs( result, result ); 375 376 376 377 // check for immediate result 377 if ( mpz_is_imm( &result ) )378 { 379 InternalCF * res = int2imm( mpz_get_si( &result ) );380 mpz_clear( &result );378 if ( mpz_is_imm( result ) ) 379 { 380 InternalCF * res = int2imm( mpz_get_si( result ) ); 381 mpz_clear( result ); 381 382 return res; 382 383 } 383 384 else 384 return new InternalInteger( result );385 return new InternalInteger( result[0] ); 385 386 } 386 387 … … 405 406 // `mpz_gcd_ui()' operates an unsigned int's only. 406 407 if ( cInt < 0 ) cInt = -cInt; 407 MP_INTdummy;408 mpz_init( &dummy );408 mpz_t dummy; 409 mpz_init( dummy ); 409 410 // we do not need dummy since we know that cInt != 0 410 cInt = mpz_gcd_ui( &dummy, &thempi, cInt );411 mpz_clear( &dummy );411 cInt = mpz_gcd_ui( dummy, &thempi, cInt ); 412 mpz_clear( dummy ); 412 413 if ( cInt < 0 ) cInt = -cInt; 413 414 return int2imm( cInt ); … … 429 430 430 431 // calculate extended gcd 431 MP_INT result; 432 MP_INT aMPI; 433 MP_INT bMPI; 434 mpz_init( &result ); 435 mpz_init( &aMPI ); 436 mpz_init( &bMPI ); 437 mpz_gcdext( &result, &aMPI, &bMPI, &thempi, &MPI( c ) ); 432 mpz_t result, aMPI, bMPI; 433 mpz_init( result ); 434 mpz_init( aMPI ); 435 mpz_init( bMPI ); 436 mpz_gcdext( result, aMPI, bMPI, &thempi, &MPI( c ) ); 438 437 439 438 // check and modify signs 440 if ( mpz_sgn( &result ) < 0 )441 { 442 mpz_neg( &result, &result );443 mpz_neg( &aMPI, &aMPI );444 mpz_neg( &bMPI, &bMPI );439 if ( mpz_sgn( result ) < 0 ) 440 { 441 mpz_neg( result, result ); 442 mpz_neg( aMPI, aMPI ); 443 mpz_neg( bMPI, bMPI ); 445 444 } 446 445 447 446 // postconditioning of result 448 if ( mpz_is_imm( &aMPI ) )449 { 450 a = CanonicalForm( int2imm( mpz_get_si( &aMPI ) ) );451 mpz_clear( &aMPI );452 } 453 else 454 a = CanonicalForm( new InternalInteger( aMPI ) );455 if ( mpz_is_imm( &bMPI ) )456 { 457 b = CanonicalForm( int2imm( mpz_get_si( &bMPI ) ) );458 mpz_clear( &bMPI );459 } 460 else 461 b = CanonicalForm( new InternalInteger( bMPI ) );462 if ( mpz_is_imm( &result ) )463 { 464 InternalCF * res = int2imm( mpz_get_si( &result ) );465 mpz_clear( &result );447 if ( mpz_is_imm( aMPI ) ) 448 { 449 a = CanonicalForm( int2imm( mpz_get_si( aMPI ) ) ); 450 mpz_clear( aMPI ); 451 } 452 else 453 a = CanonicalForm( new InternalInteger( aMPI[0] ) ); 454 if ( mpz_is_imm( bMPI ) ) 455 { 456 b = CanonicalForm( int2imm( mpz_get_si( bMPI ) ) ); 457 mpz_clear( bMPI ); 458 } 459 else 460 b = CanonicalForm( new InternalInteger( bMPI[0] ) ); 461 if ( mpz_is_imm( result ) ) 462 { 463 InternalCF * res = int2imm( mpz_get_si( result ) ); 464 mpz_clear( result ); 466 465 return res; 467 466 } 468 467 else 469 return new InternalInteger( result );468 return new InternalInteger( result[0] ); 470 469 } 471 470 … … 539 538 { 540 539 ASSERT( mpz_cmp_si( &thempi, 0 ) >= 0, "sqrt() argument < 0" ); 541 MP_INTresult;542 mpz_init( &result );543 mpz_sqrt( &result, &thempi );544 if ( mpz_is_imm( &result ) )545 { 546 InternalCF * res = int2imm( mpz_get_si( &result ) );547 mpz_clear( &result );540 mpz_t result; 541 mpz_init( result ); 542 mpz_sqrt( result, &thempi ); 543 if ( mpz_is_imm( result ) ) 544 { 545 InternalCF * res = int2imm( mpz_get_si( result ) ); 546 mpz_clear( result ); 548 547 return res; 549 548 } 550 549 else 551 return new InternalInteger( result );550 return new InternalInteger( result[0] ); 552 551 } 553 552 //}}} -
factory/singext.cc
rfd08e7 r186402 61 61 62 62 CanonicalForm 63 make_cf ( const mpz_ptrn )63 make_cf ( const MP_INT & n ) 64 64 { 65 return CanonicalForm( CFFactory::basic( *n ) );65 return CanonicalForm( CFFactory::basic( n ) ); 66 66 } 67 67 68 68 CanonicalForm 69 make_cf ( const mpz_ptr n, const mpz_ptrd, bool normalize )69 make_cf ( const MP_INT & n, const MP_INT & d, bool normalize ) 70 70 { 71 return CanonicalForm( CFFactory::rational( *n, *d, normalize ) );71 return CanonicalForm( CFFactory::rational( n, d, normalize ) ); 72 72 } 73 73 -
factory/singext.h
rfd08e7 r186402 34 34 int gf_value (const CanonicalForm & f ); 35 35 36 CanonicalForm make_cf ( const mpz_ptrn );36 CanonicalForm make_cf ( const MP_INT & n ); 37 37 38 CanonicalForm make_cf ( const mpz_ptr n, const mpz_ptrd, bool normalize );38 CanonicalForm make_cf ( const MP_INT & n, const MP_INT & d, bool normalize ); 39 39 40 40 CanonicalForm make_cf_from_gf ( const int z );
Note: See TracChangeset
for help on using the changeset viewer.