Changeset a52291 in git
- Timestamp:
- Nov 24, 2011, 2:35:53 PM (11 years ago)
- Branches:
- (u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a800fe4b3e9d37a38c5a10cc0ae9dfa0c15a4ee6')
- 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
- Location:
- factory
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
factory/NTLconvert.cc
r1c48503 ra52291 653 653 char* stringtemp; 654 654 655 gmp_val[0]= getmpi(f.getval());655 gmp_val[0]=*getmpi(f.getval()); 656 656 int l=mpz_sizeinbase(gmp_val,10)+2; 657 657 stringtemp=(char*)Alloc(l); -
factory/cf_factory.cc
r1c48503 ra52291 221 221 222 222 InternalCF * 223 CFFactory::basic ( const MP_INT &num )223 CFFactory::basic ( const mpz_ptr num ) 224 224 { 225 225 if ( currenttype != IntegerDomain ) { … … 239 239 240 240 InternalCF * 241 CFFactory::rational ( const MP_INT & num, const MP_INT &den, bool normalize )241 CFFactory::rational ( const mpz_ptr num, const mpz_ptr den, bool normalize ) 242 242 { 243 243 if ( normalize ) { … … 267 267 } 268 268 269 MP_INTgetmpi ( InternalCF * value, bool symmetric )269 mpz_ptr getmpi ( InternalCF * value, bool symmetric ) 270 270 { 271 271 ASSERT( ! is_imm( value ) && ( value->levelcoeff() == PrimePowerDomain || value->levelcoeff() == IntegerDomain ), "illegal operation" ); 272 MP_INT dummy;272 mpz_ptr dummy= new mpz_t; 273 273 if ( value->levelcoeff() == IntegerDomain ) 274 mpz_init_set( &dummy, &InternalInteger::MPI( value ) );274 mpz_init_set( dummy, InternalInteger::MPI( value ) ); 275 275 else if ( symmetric ) { 276 mpz_init( &dummy );277 if ( mpz_cmp( &InternalPrimePower::primepowhalf, &InternalPrimePower::MPI( value ) ) < 0 )278 mpz_sub( &dummy, &InternalPrimePower::MPI( value ), &InternalPrimePower::primepow );279 else 280 mpz_set( &dummy, &InternalPrimePower::MPI( value ) );281 } 282 else 283 mpz_init_set( &dummy, &InternalPrimePower::MPI( value ) );276 mpz_init( dummy ); 277 if ( mpz_cmp( InternalPrimePower::primepowhalf, InternalPrimePower::MPI( value ) ) < 0 ) 278 mpz_sub( dummy, InternalPrimePower::MPI( value ), InternalPrimePower::primepow ); 279 else 280 mpz_set( dummy, InternalPrimePower::MPI( value ) ); 281 } 282 else 283 mpz_init_set( dummy, InternalPrimePower::MPI( value ) ); 284 284 return dummy; 285 285 } -
factory/cf_factory.h
r1c48503 ra52291 28 28 static InternalCF * basic ( int type, const char * const str ); 29 29 static InternalCF * basic ( int type, int value, bool nonimm ); 30 static InternalCF * basic ( const MP_INT &num );30 static InternalCF * basic ( const mpz_ptr num ); 31 31 static InternalCF * rational ( int num, int den ); 32 static InternalCF * rational ( const MP_INT & num, const MP_INT &den, bool normalize );32 static InternalCF * rational ( const mpz_ptr num, const mpz_ptr den, bool normalize ); 33 33 static InternalCF * poly ( const Variable & v, int exp, const CanonicalForm & c ); 34 34 static InternalCF * poly ( const Variable & v, int exp = 1 ); 35 35 }; 36 36 37 38 MP_INT getmpi ( InternalCF * value, bool symmetric = true ); 37 mpz_ptr getmpi ( InternalCF * value, bool symmetric = true ); 39 38 40 39 #endif /* ! INCL_CF_FACTORY_H */ -
factory/fac_cantzass.cc
r1c48503 ra52291 19 19 static CFFList CantorZassenhausFactorFFGF( const CanonicalForm & f, int d, int q, const CFRandom & ); 20 20 21 static CFFList CantorZassenhausFactorExt( const CanonicalForm & g, int s, MP_INT *q, const CFRandom & gen );21 static CFFList CantorZassenhausFactorExt( const CanonicalForm & g, int s, mpz_t q, const CFRandom & gen ); 22 22 23 23 static CFFList distinctDegreeFactorFFGF ( const CanonicalForm & f, int q ); … … 37 37 static CanonicalForm powerMod2( const CanonicalForm & f, int p, int s, const CanonicalForm & d ); 38 38 39 static CanonicalForm powerMod2( const CanonicalForm & f, MP_INT *q, int s, const CanonicalForm & d );39 static CanonicalForm powerMod2( const CanonicalForm & f, mpz_t q, int s, const CanonicalForm & d ); 40 40 41 41 CFFList FpFactorizeUnivariateCZ( const CanonicalForm& f, bool issqrfree, int numext, const Variable alpha, const Variable beta ) … … 46 46 int d, q, n = 0; 47 47 bool galoisfield = getGFDegree() > 1; 48 MP_INTqq;48 mpz_t qq; 49 49 50 50 if ( galoisfield ) … … 57 57 else 58 58 n = getMipo( alpha ).degree() * getMipo( beta ).degree(); 59 mpz_init( &qq );60 mpz_ui_pow_ui ( &qq, q, n );59 mpz_init( qq ); 60 mpz_ui_pow_ui ( qq, q, n ); 61 61 } 62 62 if ( LC( f ).isOne() ) … … 82 82 if ( numext == 1 ) { 83 83 AlgExtRandomF tmpalpha( alpha ); 84 HH = CantorZassenhausFactorExt( j.getItem().factor(), j.getItem().exp(), &qq, tmpalpha );84 HH = CantorZassenhausFactorExt( j.getItem().factor(), j.getItem().exp(), qq, tmpalpha ); 85 85 } 86 86 else { 87 87 AlgExtRandomF tmpalphabeta( alpha, beta ); 88 HH = CantorZassenhausFactorExt( j.getItem().factor(), j.getItem().exp(), &qq, tmpalphabeta );88 HH = CantorZassenhausFactorExt( j.getItem().factor(), j.getItem().exp(), qq, tmpalphabeta ); 89 89 } 90 90 } … … 100 100 } 101 101 if ( numext > 0 ) 102 mpz_clear( &qq );102 mpz_clear( qq ); 103 103 return H; 104 104 } … … 171 171 } 172 172 173 CFFList CantorZassenhausFactorExt( const CanonicalForm & g, int s, MP_INT *q, const CFRandom & gen )173 CFFList CantorZassenhausFactorExt( const CanonicalForm & g, int s, mpz_t q, const CFRandom & gen ) 174 174 { 175 175 CanonicalForm f = g; … … 228 228 int odd; 229 229 230 MP_INTm;231 232 mpz_init( &m );233 mpz_ui_pow_ui ( &m, p, s );234 while ( mpz_cmp_si( &m, 0 ) != 0 )230 mpz_t m; 231 232 mpz_init( m ); 233 mpz_ui_pow_ui ( m, p, s ); 234 while ( mpz_cmp_si( m, 0 ) != 0 ) 235 235 { 236 odd = mpz_fdiv_q_ui( &m, &m, 2 );236 odd = mpz_fdiv_q_ui( m, m, 2 ); 237 237 if ( odd != 0 ) 238 238 prod = (prod * b) % d; 239 if ( mpz_cmp_si( &m, 0 ) != 0 )239 if ( mpz_cmp_si( m, 0 ) != 0 ) 240 240 b = (b*b) % d; 241 241 } 242 mpz_clear( &m );242 mpz_clear( m ); 243 243 return prod; 244 244 } … … 250 250 int odd; 251 251 252 MP_INTm;253 254 mpz_init( &m );255 mpz_ui_pow_ui ( &m, p, s );256 mpz_sub_ui( &m, &m, 1 );257 mpz_fdiv_q_ui( &m, &m, 2 );258 while ( mpz_cmp_si( &m, 0 ) != 0 )252 mpz_t m; 253 254 mpz_init( m ); 255 mpz_ui_pow_ui ( m, p, s ); 256 mpz_sub_ui( m, m, 1 ); 257 mpz_fdiv_q_ui( m, m, 2 ); 258 while ( mpz_cmp_si( m, 0 ) != 0 ) 259 259 { 260 odd = mpz_fdiv_q_ui( &m, &m, 2 );260 odd = mpz_fdiv_q_ui( m, m, 2 ); 261 261 if ( odd != 0 ) 262 262 prod = (prod * b) % d; 263 if ( mpz_cmp_si( &m, 0 ) != 0 )263 if ( mpz_cmp_si( m, 0 ) != 0 ) 264 264 b = (b*b) % d; 265 265 } 266 mpz_clear( &m );267 return prod; 268 } 269 270 CanonicalForm powerMod2( const CanonicalForm & f, MP_INT *q, int s, const CanonicalForm & d )266 mpz_clear( m ); 267 return prod; 268 } 269 270 CanonicalForm powerMod2( const CanonicalForm & f, mpz_t q, int s, const CanonicalForm & d ) 271 271 { 272 272 CanonicalForm prod = 1; … … 274 274 int odd; 275 275 276 MP_INTm;277 278 mpz_init( &m );279 mpz_pow_ui( &m, q, s );280 mpz_sub_ui( &m, &m, 1 );281 mpz_fdiv_q_ui( &m, &m, 2 );282 while ( mpz_cmp_si( &m, 0 ) != 0 )276 mpz_t m; 277 278 mpz_init( m ); 279 mpz_pow_ui( m, q, s ); 280 mpz_sub_ui( m, m, 1 ); 281 mpz_fdiv_q_ui( m, m, 2 ); 282 while ( mpz_cmp_si( m, 0 ) != 0 ) 283 283 { 284 odd = mpz_fdiv_q_ui( &m, &m, 2 );284 odd = mpz_fdiv_q_ui( m, m, 2 ); 285 285 if ( odd != 0 ) 286 286 prod = (prod * b) % d; 287 if ( mpz_cmp_si( &m, 0 ) != 0 )287 if ( mpz_cmp_si( m, 0 ) != 0 ) 288 288 b = (b*b) % d; 289 289 } 290 mpz_clear( &m );291 return prod; 292 } 290 mpz_clear( m ); 291 return prod; 292 } -
factory/gmpext.h
r1c48503 ra52291 13 13 14 14 inline bool 15 mpz_is_imm( const MP_INT *mpi )15 mpz_is_imm( const mpz_t mpi ) 16 16 { 17 17 return ( mpz_cmp_si( mpi, MINIMMEDIATE ) >= 0 ) && -
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 //}}} -
factory/int_int.h
r1c48503 ra52291 31 31 { 32 32 private: 33 MP_INTthempi;33 mpz_t thempi; 34 34 35 35 // auxilliary methods … … 37 37 inline InternalCF * uiNormalizeMyself (); 38 38 39 static inline InternalCF * normalizeMPI ( MP_INT &);40 static inline InternalCF * uiNormalizeMPI ( MP_INT &);41 42 static inline MP_INT &MPI ( const InternalCF * const c );39 static inline InternalCF * normalizeMPI ( mpz_ptr ); 40 static inline InternalCF * uiNormalizeMPI ( mpz_ptr ); 41 42 static inline mpz_ptr MPI ( const InternalCF * const c ); 43 43 #ifdef HAVE_OMALLOC 44 44 static const omBin InternalInteger_bin; … … 65 65 InternalInteger( const int i ); 66 66 InternalInteger( const char * str, const int base=10 ); 67 InternalInteger( const MP_INT &);67 InternalInteger( const mpz_ptr ); 68 68 ~InternalInteger(); 69 69 InternalCF* deepCopyObject() const; … … 123 123 friend void gmp_numerator ( const CanonicalForm & f, mpz_ptr result); 124 124 friend void gmp_denominator ( const CanonicalForm & f, mpz_ptr result ); 125 friend MP_INTgetmpi ( InternalCF * value, bool symmetric );125 friend mpz_ptr getmpi ( InternalCF * value, bool symmetric ); 126 126 }; 127 127 … … 148 148 ASSERT( getRefCount() == 1, "internal error: must not delete CO" ); 149 149 150 if ( mpz_is_imm( &thempi ) ) {151 InternalCF * result = int2imm( mpz_get_si( &thempi ) );150 if ( mpz_is_imm( thempi ) ) { 151 InternalCF * result = int2imm( mpz_get_si( thempi ) ); 152 152 delete this; 153 153 return result; … … 161 161 ASSERT( getRefCount() == 1, "internal error: must not delete CO" ); 162 162 163 if ( mpz_is_imm( &thempi ) ) {164 InternalCF * result = int2imm( mpz_get_ui( &thempi ) );163 if ( mpz_is_imm( thempi ) ) { 164 InternalCF * result = int2imm( mpz_get_ui( thempi ) ); 165 165 delete this; 166 166 return result; … … 170 170 //}}} 171 171 172 //{{{ static inline InternalCF * InternalInteger::normalizeMPI, uiNormalizeMPI ( MP_INT &aMpi )172 //{{{ static inline InternalCF * InternalInteger::normalizeMPI, uiNormalizeMPI ( mpz_ptr aMpi ) 173 173 //{{{ docu 174 174 // … … 186 186 //}}} 187 187 inline InternalCF * 188 InternalInteger::normalizeMPI ( MP_INT &aMpi )189 { 190 if ( mpz_is_imm( &aMpi ) ) {191 InternalCF * result = int2imm( mpz_get_si( &aMpi ) );192 mpz_clear( &aMpi );188 InternalInteger::normalizeMPI ( mpz_ptr aMpi ) 189 { 190 if ( mpz_is_imm( aMpi ) ) { 191 InternalCF * result = int2imm( mpz_get_si( aMpi ) ); 192 mpz_clear( aMpi ); 193 193 return result; 194 194 } else … … 197 197 198 198 inline InternalCF * 199 InternalInteger::uiNormalizeMPI ( MP_INT &aMpi )200 { 201 if ( mpz_is_imm( &aMpi ) ) {202 InternalCF * result = int2imm( mpz_get_ui( &aMpi ) );203 mpz_clear( &aMpi );199 InternalInteger::uiNormalizeMPI ( mpz_ptr aMpi ) 200 { 201 if ( mpz_is_imm( aMpi ) ) { 202 InternalCF * result = int2imm( mpz_get_ui( aMpi ) ); 203 mpz_clear( aMpi ); 204 204 return result; 205 205 } else … … 208 208 //}}} 209 209 210 //{{{ inline MP_INT &InternalInteger::MPI ( const InternalCF * const c )210 //{{{ inline mpz_ptr InternalInteger::MPI ( const InternalCF * const c ) 211 211 //{{{ docu 212 212 // … … 217 217 // 218 218 //}}} 219 inline MP_INT &219 inline mpz_ptr 220 220 InternalInteger::MPI ( const InternalCF * const c ) 221 221 { -
factory/int_intdiv.cc
r1c48503 ra52291 33 33 34 34 if ( cf_glob_switches.isOn( SW_RATIONAL ) ) { 35 MP_INTn, d;36 mpz_init_set( &n, &thempi );37 mpz_init_set( &d, &MPI( c ) );35 mpz_t n, d; 36 mpz_init_set( n, thempi ); 37 mpz_init_set( d, MPI( c ) ); 38 38 if ( deleteObject() ) delete this; 39 39 InternalRational * result = new InternalRational( n, d ); … … 43 43 if ( getRefCount() > 1 ) { 44 44 decRefCount(); 45 MP_INTmpiResult;46 mpz_init( &mpiResult );47 if ( mpz_sgn( &MPI( c ) ) > 0 )48 mpz_fdiv_q( &mpiResult, &thempi, &MPI( c ) );45 mpz_t mpiResult; 46 mpz_init( mpiResult ); 47 if ( mpz_sgn( MPI( c ) ) > 0 ) 48 mpz_fdiv_q( mpiResult, thempi, MPI( c ) ); 49 49 else 50 mpz_cdiv_q( &mpiResult, &thempi, &MPI( c ) );50 mpz_cdiv_q( mpiResult, thempi, MPI( c ) ); 51 51 return normalizeMPI( mpiResult ); 52 52 } else { 53 if ( mpz_sgn( &MPI( c ) ) > 0 )54 mpz_fdiv_q( &thempi, &thempi, &MPI( c ) );53 if ( mpz_sgn( MPI( c ) ) > 0 ) 54 mpz_fdiv_q( thempi, thempi, MPI( c ) ); 55 55 else 56 mpz_cdiv_q( &thempi, &thempi, &MPI( c ) );56 mpz_cdiv_q( thempi, thempi, MPI( c ) ); 57 57 return normalizeMyself(); 58 58 } … … 70 70 71 71 if ( cf_glob_switches.isOn( SW_RATIONAL ) ) { 72 MP_INTn, d;72 mpz_t n, d; 73 73 if ( invert ) { 74 mpz_init_set_si( &n, intC );75 mpz_init_set( &d, &thempi );76 } else { 77 mpz_init_set( &n, &thempi );78 mpz_init_set_si( &d, intC );74 mpz_init_set_si( n, intC ); 75 mpz_init_set( d, thempi ); 76 } else { 77 mpz_init_set( n, thempi ); 78 mpz_init_set_si( d, intC ); 79 79 } 80 80 if ( deleteObject() ) delete this; … … 84 84 85 85 if ( invert ) { 86 int mpiSign = mpz_sgn( &thempi );86 int mpiSign = mpz_sgn( thempi ); 87 87 if ( deleteObject() ) delete this; 88 88 if ( intC >= 0 ) … … 92 92 } else if ( getRefCount() > 1 ) { 93 93 decRefCount(); 94 MP_INTmpiResult;95 mpz_init( &mpiResult );94 mpz_t mpiResult; 95 mpz_init( mpiResult ); 96 96 if ( intC > 0 ) 97 mpz_fdiv_q_ui( &mpiResult, &thempi, intC );97 mpz_fdiv_q_ui( mpiResult, thempi, intC ); 98 98 else { 99 mpz_fdiv_q_ui( &mpiResult, &thempi, -intC );100 mpz_neg( &mpiResult, &mpiResult );99 mpz_fdiv_q_ui( mpiResult, thempi, -intC ); 100 mpz_neg( mpiResult, mpiResult ); 101 101 } 102 102 return normalizeMPI( mpiResult ); 103 103 } else { 104 104 if ( intC > 0 ) 105 mpz_fdiv_q_ui( &thempi, &thempi, intC );105 mpz_fdiv_q_ui( thempi, thempi, intC ); 106 106 else { 107 mpz_fdiv_q_ui( &thempi, &thempi, -intC );108 mpz_neg( &thempi, &thempi );107 mpz_fdiv_q_ui( thempi, thempi, -intC ); 108 mpz_neg( thempi, thempi ); 109 109 } 110 110 return normalizeMyself(); … … 128 128 if ( getRefCount() > 1 ) { 129 129 deleteObject(); 130 MP_INTmpiResult;131 mpz_init( &mpiResult );132 mpz_divexact( &mpiResult, &thempi, &MPI( c ) );130 mpz_t mpiResult; 131 mpz_init( mpiResult ); 132 mpz_divexact( mpiResult, thempi, MPI( c ) ); 133 133 return normalizeMPI( mpiResult ); 134 134 } else { 135 mpz_divexact( &thempi, &thempi, &MPI( c ) );135 mpz_divexact( thempi, thempi, MPI( c ) ); 136 136 return normalizeMyself(); 137 137 } … … 154 154 } else if ( getRefCount() > 1 ) { 155 155 deleteObject(); 156 MP_INTmpiC;157 MP_INTmpiResult;158 mpz_init_set_si( &mpiC, imm2int( c ) );159 mpz_init( &mpiResult );160 mpz_divexact( &mpiResult, &thempi, &mpiC );161 mpz_clear( &mpiC );156 mpz_t mpiC; 157 mpz_t mpiResult; 158 mpz_init_set_si( mpiC, imm2int( c ) ); 159 mpz_init( mpiResult ); 160 mpz_divexact( mpiResult, thempi, mpiC ); 161 mpz_clear( mpiC ); 162 162 return normalizeMPI( mpiResult ); 163 163 } else { 164 MP_INTmpiC;165 mpz_init_set_si( &mpiC, imm2int( c ) );166 mpz_divexact( &thempi, &thempi, &mpiC );167 mpz_clear( &mpiC );164 mpz_t mpiC; 165 mpz_init_set_si( mpiC, imm2int( c ) ); 166 mpz_divexact( thempi, thempi, mpiC ); 167 mpz_clear( mpiC ); 168 168 return normalizeMyself(); 169 169 } … … 186 186 if ( getRefCount() > 1 ) { 187 187 decRefCount(); 188 MP_INTmpiResult;189 mpz_init( &mpiResult );190 mpz_mod( &mpiResult, &thempi, &MPI( c ) );188 mpz_t mpiResult; 189 mpz_init( mpiResult ); 190 mpz_mod( mpiResult, thempi, MPI( c ) ); 191 191 return uiNormalizeMPI( mpiResult ); 192 192 } else { 193 mpz_mod( &thempi, &thempi, &MPI( c ) );193 mpz_mod( thempi, thempi, MPI( c ) ); 194 194 return uiNormalizeMyself(); 195 195 } … … 217 217 } else { 218 218 // no checks for refCount == 1 are done. It is not worth ... 219 MP_INTmpiResult;220 mpz_init_set( &mpiResult, &thempi );221 mpz_abs( &mpiResult, &mpiResult );222 mpz_sub_ui( &mpiResult, &mpiResult, -intC );219 mpz_t mpiResult; 220 mpz_init_set( mpiResult, thempi ); 221 mpz_abs( mpiResult, mpiResult ); 222 mpz_sub_ui( mpiResult, mpiResult, -intC ); 223 223 if ( deleteObject() ) delete this; 224 224 return uiNormalizeMPI( mpiResult ); 225 225 } 226 226 } else { 227 MP_INTdummy;228 mpz_init( &dummy );229 InternalCF * result = int2imm( mpz_mod_ui( &dummy, &thempi, tabs( intC ) ) );230 mpz_clear( &dummy );227 mpz_t dummy; 228 mpz_init( dummy ); 229 InternalCF * result = int2imm( mpz_mod_ui( dummy, thempi, tabs( intC ) ) ); 230 mpz_clear( dummy ); 231 231 if ( deleteObject() ) delete this; 232 232 return result; … … 265 265 266 266 if ( cf_glob_switches.isOn( SW_RATIONAL ) ) { 267 MP_INTn, d;268 mpz_init_set( &n, &thempi );269 mpz_init_set( &d, &MPI( c ) );267 mpz_t n, d; 268 mpz_init_set( n, thempi ); 269 mpz_init_set( d, MPI( c ) ); 270 270 InternalRational * result = new InternalRational( n, d ); 271 271 quot = result->normalize_myself(); … … 274 274 } 275 275 276 MP_INTq;277 MP_INTr;278 mpz_init( &q ); mpz_init( &r );279 if ( mpz_sgn( &MPI( c ) ) > 0 )280 mpz_fdiv_qr( &q, &r, &thempi, &MPI( c ) );276 mpz_t q; 277 mpz_t r; 278 mpz_init( q ); mpz_init( r ); 279 if ( mpz_sgn( MPI( c ) ) > 0 ) 280 mpz_fdiv_qr( q, r, thempi, MPI( c ) ); 281 281 else 282 mpz_cdiv_qr( &q, &r, &thempi, &MPI( c ) );282 mpz_cdiv_qr( q, r, thempi, MPI( c ) ); 283 283 284 284 quot = normalizeMPI( q ); … … 297 297 298 298 if ( cf_glob_switches.isOn( SW_RATIONAL ) ) { 299 MP_INTn, d;299 mpz_t n, d; 300 300 if ( invert ) { 301 mpz_init_set_si( &n, intC );302 mpz_init_set( &d, &thempi );303 } else { 304 mpz_init_set( &n, &thempi );305 mpz_init_set_si( &d, intC );301 mpz_init_set_si( n, intC ); 302 mpz_init_set( d, thempi ); 303 } else { 304 mpz_init_set( n, thempi ); 305 mpz_init_set_si( d, intC ); 306 306 } 307 307 InternalRational * result = new InternalRational( n, d ); … … 316 316 quot = int2imm( 0 ); 317 317 } else { 318 MP_INTmpiResult;319 mpz_init_set( &mpiResult, &thempi );320 mpz_abs( &mpiResult, &mpiResult );321 mpz_sub_ui( &mpiResult, &mpiResult, -intC );318 mpz_t mpiResult; 319 mpz_init_set( mpiResult, thempi ); 320 mpz_abs( mpiResult, mpiResult ); 321 mpz_sub_ui( mpiResult, mpiResult, -intC ); 322 322 rem = uiNormalizeMPI( mpiResult ); 323 quot = int2imm( -mpz_sgn( &thempi ) );324 } 325 } else { 326 MP_INTq;327 MP_INTdummy;328 mpz_init( &q ); mpz_init( &dummy );323 quot = int2imm( -mpz_sgn( thempi ) ); 324 } 325 } else { 326 mpz_t q; 327 mpz_t dummy; 328 mpz_init( q ); mpz_init( dummy ); 329 329 if ( intC > 0 ) { 330 rem = int2imm( mpz_fdiv_qr_ui( &q, &dummy, &thempi, intC ) );330 rem = int2imm( mpz_fdiv_qr_ui( q, dummy, thempi, intC ) ); 331 331 quot = normalizeMPI( q ); 332 332 } else { 333 rem = int2imm( mpz_fdiv_qr_ui( &q, &dummy, &thempi, -intC ) );334 mpz_neg( &q, &q );333 rem = int2imm( mpz_fdiv_qr_ui( q, dummy, thempi, -intC ) ); 334 mpz_neg( q, q ); 335 335 quot = normalizeMPI( q ); 336 336 } 337 mpz_clear( &dummy );337 mpz_clear( dummy ); 338 338 } 339 339 } -
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 //}}} -
factory/int_pp.h
r1c48503 ra52291 27 27 { 28 28 private: 29 MP_INTthempi;29 mpz_t thempi; 30 30 static int initialized; 31 31 static int prime; 32 32 static int exp; 33 static MP_INTprimepow;34 static MP_INTprimepowhalf;33 static mpz_t primepow; 34 static mpz_t primepowhalf; 35 35 static int initialize(); 36 static MP_INT &MPI( const InternalCF * const c );36 static mpz_ptr MPI( const InternalCF * const c ); 37 37 public: 38 38 InternalPrimePower(); … … 43 43 InternalPrimePower( const int i ); 44 44 InternalPrimePower( const char * str, const int base=10 ); 45 InternalPrimePower( const MP_INT &);45 InternalPrimePower( const mpz_ptr ); 46 46 ~InternalPrimePower(); 47 47 InternalCF* deepCopyObject() const; … … 94 94 95 95 int sign() const; 96 friend MP_INTgetmpi ( InternalCF * value, bool symmetric );96 friend mpz_ptr getmpi ( InternalCF * value, bool symmetric ); 97 97 }; 98 98 99 inline MP_INT &InternalPrimePower::MPI( const InternalCF * const c )99 inline mpz_ptr InternalPrimePower::MPI( const InternalCF * const c ) 100 100 { 101 101 return (((InternalPrimePower*)c)->thempi); -
factory/int_rat.cc
r1c48503 ra52291 33 33 InternalRational::InternalRational() 34 34 { 35 mpz_init( &_num );36 mpz_init_set_si( &_den, 1 );35 mpz_init( _num ); 36 mpz_init_set_si( _den, 1 ); 37 37 } 38 38 39 39 InternalRational::InternalRational( const int i ) 40 40 { 41 mpz_init_set_si( &_num, i );42 mpz_init_set_si( &_den, 1 );41 mpz_init_set_si( _num, i ); 42 mpz_init_set_si( _den, 1 ); 43 43 } 44 44 … … 48 48 if ( n == 0 ) 49 49 { 50 mpz_init_set_si( &_num, 0 );51 mpz_init_set_si( &_den, 1 );50 mpz_init_set_si( _num, 0 ); 51 mpz_init_set_si( _den, 1 ); 52 52 } 53 53 else 54 54 { 55 55 int g = intgcd( n, d ); 56 if ( d < 0 ) g= -g; 57 mpz_init_set_si( &_num, n / g ); 58 mpz_init_set_si( &_den, d / g ); 56 if ( d < 0 ) 57 { 58 mpz_init_set_si( _num, -n / g ); 59 mpz_init_set_si( _den, -d / g ); 60 } 61 else 62 { 63 mpz_init_set_si( _num, n / g ); 64 mpz_init_set_si( _den, d / g ); 65 } 59 66 } 60 67 } … … 64 71 // sollte nicht gebraucht werden !!! 65 72 ASSERT( 0, "fatal error" ); 66 mpz_init( &_num ); 67 mpz_init( &_den ); 68 } 69 70 InternalRational::InternalRational( const MP_INT &n ) : _num(n) 71 { 72 mpz_init_set_si( &_den, 1 ); 73 } 74 75 InternalRational::InternalRational( const MP_INT &n, const MP_INT &d ) : _num(n), _den(d) 76 { 73 mpz_init( _num ); 74 mpz_init( _den ); 75 } 76 77 //InternalRational::InternalRational( const mpz_ptr n ) : _num(n) 78 //{ 79 // mpz_init_set_si( _den, 1 ); 80 //} 81 82 InternalRational::InternalRational( const mpz_ptr n ) 83 { 84 _num[0]=*n; 85 mpz_init_set_si( _den, 1 ); 86 } 87 88 InternalRational::InternalRational( const mpz_ptr n, const mpz_ptr d ) 89 { 90 _num[0]=*n; 91 _den[0]=*d; 77 92 } 78 93 79 94 InternalRational::~InternalRational() 80 95 { 81 mpz_clear( &_num );82 mpz_clear( &_den );96 mpz_clear( _num ); 97 mpz_clear( _den ); 83 98 } 84 99 85 100 InternalCF* InternalRational::deepCopyObject() const 86 101 { 87 MP_INTdummy_num;88 MP_INTdummy_den;89 mpz_init_set( &dummy_num, &_num );90 mpz_init_set( &dummy_den, &_den );102 mpz_t dummy_num; 103 mpz_t dummy_den; 104 mpz_init_set( dummy_num, _num ); 105 mpz_init_set( dummy_den, _den ); 91 106 return new InternalRational( dummy_num, dummy_den ); 92 107 } … … 95 110 void InternalRational::print( OSTREAM & os, char * c ) 96 111 { 97 char * str = new char[mpz_sizeinbase( &_num, 10 ) + 2];98 str = mpz_get_str( str, 10, &_num );112 char * str = new char[mpz_sizeinbase( _num, 10 ) + 2]; 113 str = mpz_get_str( str, 10, _num ); 99 114 os << str << '/'; 100 115 delete [] str; 101 str = new char[mpz_sizeinbase( &_den, 10 ) + 2];102 str = mpz_get_str( str, 10, &_den );116 str = new char[mpz_sizeinbase( _den, 10 ) + 2]; 117 str = mpz_get_str( str, 10, _den ); 103 118 os << str << c; 104 119 delete [] str; … … 108 123 bool InternalRational::is_imm() const 109 124 { 110 return mpz_cmp_si( &_den, 1 ) == 0 && mpz_is_imm( &_num );125 return mpz_cmp_si( _den, 1 ) == 0 && mpz_is_imm( _num ); 111 126 } 112 127 … … 131 146 InternalCF * InternalRational::num () 132 147 { 133 if ( mpz_is_imm( &_num ) )134 { 135 InternalCF * res = int2imm( mpz_get_si( &_num ) );148 if ( mpz_is_imm( _num ) ) 149 { 150 InternalCF * res = int2imm( mpz_get_si( _num ) ); 136 151 return res; 137 152 } 138 153 else 139 154 { 140 MP_INTdummy;141 mpz_init_set( &dummy, &_num );155 mpz_t dummy; 156 mpz_init_set( dummy, _num ); 142 157 return new InternalInteger( dummy ); 143 158 } … … 146 161 InternalCF * InternalRational::den () 147 162 { 148 if ( mpz_is_imm( &_den ) )149 { 150 InternalCF * res = int2imm( mpz_get_si( &_den ) );163 if ( mpz_is_imm( _den ) ) 164 { 165 InternalCF * res = int2imm( mpz_get_si( _den ) ); 151 166 return res; 152 167 } 153 168 else 154 169 { 155 MP_INTdummy;156 mpz_init_set( &dummy, &_den );170 mpz_t dummy; 171 mpz_init_set( dummy, _den ); 157 172 return new InternalInteger( dummy ); 158 173 } … … 168 183 { 169 184 decRefCount(); 170 MP_INTdummy_num;171 MP_INTdummy_den;172 mpz_init_set( &dummy_num, &_num );173 mpz_init_set( &dummy_den, &_den );174 mpz_neg( &dummy_num, &dummy_num );185 mpz_t dummy_num; 186 mpz_t dummy_den; 187 mpz_init_set( dummy_num, _num ); 188 mpz_init_set( dummy_den, _den ); 189 mpz_neg( dummy_num, dummy_num ); 175 190 return new InternalRational( dummy_num, dummy_den ); 176 191 } 177 192 else 178 193 { 179 mpz_neg( &_num, &_num );194 mpz_neg( _num, _num ); 180 195 return this; 181 196 } … … 186 201 { 187 202 ASSERT( ! ::is_imm( c ) && c->levelcoeff() == RationalDomain, "illegal domain" ); 188 MP_INTn, d, g;189 190 mpz_init( &g ); mpz_init( &n ); mpz_init( &d );191 mpz_gcd( &g, &_den, &MPQDEN( c ) );192 193 if ( mpz_cmp_si( &g, 1 ) == 0 )194 { 195 mpz_mul( &n, &_den, &MPQNUM( c ) );196 mpz_mul( &g, &_num, &MPQDEN( c ) );197 mpz_add( &n, &n, &g );198 mpz_mul( &d, &_den, &MPQDEN( c ) );199 } 200 else 201 { 202 MP_INTtmp1;203 MP_INTtmp2;204 mpz_init( &tmp1 );205 mpz_divexact( &tmp1, &_den, &g );206 mpz_init( &tmp2 );207 mpz_divexact( &tmp2, &MPQDEN( c ), &g );208 mpz_mul( &d, &tmp2, &_den );209 mpz_mul( &tmp2, &tmp2, &_num );210 mpz_mul( &tmp1, &tmp1, &MPQNUM( c ) );211 mpz_add( &n, &tmp1, &tmp2 );212 mpz_gcd( &g, &n, &d );213 if ( mpz_cmp_si( &g, 1 ) != 0 )203 mpz_t n, d, g; 204 205 mpz_init( g ); mpz_init( n ); mpz_init( d ); 206 mpz_gcd( g, _den, MPQDEN( c ) ); 207 208 if ( mpz_cmp_si( g, 1 ) == 0 ) 209 { 210 mpz_mul( n, _den, MPQNUM( c ) ); 211 mpz_mul( g, _num, MPQDEN( c ) ); 212 mpz_add( n, n, g ); 213 mpz_mul( d, _den, MPQDEN( c ) ); 214 } 215 else 216 { 217 mpz_t tmp1; 218 mpz_t tmp2; 219 mpz_init( tmp1 ); 220 mpz_divexact( tmp1, _den, g ); 221 mpz_init( tmp2 ); 222 mpz_divexact( tmp2, MPQDEN( c ), g ); 223 mpz_mul( d, tmp2, _den ); 224 mpz_mul( tmp2, tmp2, _num ); 225 mpz_mul( tmp1, tmp1, MPQNUM( c ) ); 226 mpz_add( n, tmp1, tmp2 ); 227 mpz_gcd( g, n, d ); 228 if ( mpz_cmp_si( g, 1 ) != 0 ) 214 229 { 215 mpz_divexact( &n, &n, &g );216 mpz_divexact( &d, &d, &g );230 mpz_divexact( n, n, g ); 231 mpz_divexact( d, d, g ); 217 232 } 218 mpz_clear( &tmp1 );219 mpz_clear( &tmp2 );220 } 221 mpz_clear( &g );233 mpz_clear( tmp1 ); 234 mpz_clear( tmp2 ); 235 } 236 mpz_clear( g ); 222 237 if ( deleteObject() ) delete this; 223 if ( mpz_cmp_si( &d, 1 ) == 0 )224 { 225 mpz_clear( &d );226 if ( mpz_is_imm( &n ) )238 if ( mpz_cmp_si( d, 1 ) == 0 ) 239 { 240 mpz_clear( d ); 241 if ( mpz_is_imm( n ) ) 227 242 { 228 InternalCF * res = int2imm( mpz_get_si( &n ) );229 mpz_clear( &n );243 InternalCF * res = int2imm( mpz_get_si( n ) ); 244 mpz_clear( n ); 230 245 return res; 231 246 } … … 244 259 { 245 260 ASSERT( ! ::is_imm( c ) && c->levelcoeff() == RationalDomain, "illegal domain" ); 246 MP_INTn, d, g;247 248 mpz_init( &g ); mpz_init( &n ); mpz_init( &d );249 mpz_gcd( &g, &_den, &MPQDEN( c ) );250 251 if ( mpz_cmp_si( &g, 1 ) == 0 )252 { 253 mpz_mul( &n, &_den, &MPQNUM( c ) );254 mpz_mul( &g, &_num, &MPQDEN( c ) );255 mpz_sub( &n, &g, &n );256 mpz_mul( &d, &_den, &MPQDEN( c ) );257 } 258 else 259 { 260 MP_INTtmp1;261 MP_INTtmp2;262 mpz_init( &tmp1 );263 mpz_divexact( &tmp1, &_den, &g );264 mpz_init( &tmp2 );265 mpz_divexact( &tmp2, &MPQDEN( c ), &g );266 mpz_mul( &d, &tmp2, &_den );267 mpz_mul( &tmp2, &tmp2, &_num );268 mpz_mul( &tmp1, &tmp1, &MPQNUM( c ) );269 mpz_sub( &n, &tmp2, &tmp1 );270 mpz_gcd( &g, &n, &d );271 if ( mpz_cmp_si( &g, 1 ) != 0 )272 { 273 mpz_divexact( &n, &n, &g );274 mpz_divexact( &d, &d, &g );275 } 276 mpz_clear( &tmp1 );277 mpz_clear( &tmp2 );278 } 279 mpz_clear( &g );261 mpz_t n, d, g; 262 263 mpz_init( g ); mpz_init( n ); mpz_init( d ); 264 mpz_gcd( g, _den, MPQDEN( c ) ); 265 266 if ( mpz_cmp_si( g, 1 ) == 0 ) 267 { 268 mpz_mul( n, _den, MPQNUM( c ) ); 269 mpz_mul( g, _num, MPQDEN( c ) ); 270 mpz_sub( n, g, n ); 271 mpz_mul( d, _den, MPQDEN( c ) ); 272 } 273 else 274 { 275 mpz_t tmp1; 276 mpz_t tmp2; 277 mpz_init( tmp1 ); 278 mpz_divexact( tmp1, _den, g ); 279 mpz_init( tmp2 ); 280 mpz_divexact( tmp2, MPQDEN( c ), g ); 281 mpz_mul( d, tmp2, _den ); 282 mpz_mul( tmp2, tmp2, _num ); 283 mpz_mul( tmp1, tmp1, MPQNUM( c ) ); 284 mpz_sub( n, tmp2, tmp1 ); 285 mpz_gcd( g, n, d ); 286 if ( mpz_cmp_si( g, 1 ) != 0 ) 287 { 288 mpz_divexact( n, n, g ); 289 mpz_divexact( d, d, g ); 290 } 291 mpz_clear( tmp1 ); 292 mpz_clear( tmp2 ); 293 } 294 mpz_clear( g ); 280 295 if ( deleteObject() ) delete this; 281 if ( mpz_cmp_si( &d, 1 ) == 0 )282 { 283 mpz_clear( &d );284 if ( mpz_is_imm( &n ) )285 { 286 InternalCF * res = int2imm( mpz_get_si( &n ) );287 mpz_clear( &n );296 if ( mpz_cmp_si( d, 1 ) == 0 ) 297 { 298 mpz_clear( d ); 299 if ( mpz_is_imm( n ) ) 300 { 301 InternalCF * res = int2imm( mpz_get_si( n ) ); 302 mpz_clear( n ); 288 303 return res; 289 304 } … … 300 315 { 301 316 ASSERT( ! ::is_imm( c ) && c->levelcoeff() == RationalDomain, "illegal domain" ); 302 MP_INTn, d;303 mpz_init( &n ); mpz_init( &d );317 mpz_t n, d; 318 mpz_init( n ); mpz_init( d ); 304 319 305 320 if ( this == c ) 306 321 { 307 mpz_mul( &n, &_num, &_num );308 mpz_mul( &d, &_den, &_den );309 } 310 else 311 { 312 MP_INTg1, g2, tmp1, tmp2;313 mpz_init( &g1 ); mpz_init( &g2 );314 mpz_gcd( &g1, &_num, &MPQDEN( c ) );315 mpz_gcd( &g2, &_den, &MPQNUM( c ) );316 bool g1is1 = mpz_cmp_si( &g1, 1 ) == 0;317 bool g2is1 = mpz_cmp_si( &g2, 1 ) == 0;318 mpz_init( &tmp1 ); mpz_init( &tmp2 );322 mpz_mul( n, _num, _num ); 323 mpz_mul( d, _den, _den ); 324 } 325 else 326 { 327 mpz_t g1, g2, tmp1, tmp2; 328 mpz_init( g1 ); mpz_init( g2 ); 329 mpz_gcd( g1, _num, MPQDEN( c ) ); 330 mpz_gcd( g2, _den, MPQNUM( c ) ); 331 bool g1is1 = mpz_cmp_si( g1, 1 ) == 0; 332 bool g2is1 = mpz_cmp_si( g2, 1 ) == 0; 333 mpz_init( tmp1 ); mpz_init( tmp2 ); 319 334 if ( ! g1is1 ) 320 mpz_divexact( &tmp1, &_num, &g1 );321 else 322 mpz_set( &tmp1, &_num );335 mpz_divexact( tmp1, _num, g1 ); 336 else 337 mpz_set( tmp1, _num ); 323 338 if ( ! g2is1 ) 324 mpz_divexact( &tmp2, &MPQNUM( c ), &g2 );325 else 326 mpz_set( &tmp2, &MPQNUM( c ) );327 mpz_mul( &n, &tmp1, &tmp2 );339 mpz_divexact( tmp2, MPQNUM( c ), g2 ); 340 else 341 mpz_set( tmp2, MPQNUM( c ) ); 342 mpz_mul( n, tmp1, tmp2 ); 328 343 if ( ! g1is1 ) 329 mpz_divexact( &tmp1, &MPQDEN( c ), &g1 );330 else 331 mpz_set( &tmp1, &MPQDEN( c ) );344 mpz_divexact( tmp1, MPQDEN( c ), g1 ); 345 else 346 mpz_set( tmp1, MPQDEN( c ) ); 332 347 if ( ! g2is1 ) 333 mpz_divexact( &tmp2, &_den, &g2 );334 else 335 mpz_set( &tmp2, &_den );336 mpz_mul( &d, &tmp1, &tmp2 );337 mpz_clear( &tmp1 ); mpz_clear( &tmp2 );338 mpz_clear( &g1 ); mpz_clear( &g2 );348 mpz_divexact( tmp2, _den, g2 ); 349 else 350 mpz_set( tmp2, _den ); 351 mpz_mul( d, tmp1, tmp2 ); 352 mpz_clear( tmp1 ); mpz_clear( tmp2 ); 353 mpz_clear( g1 ); mpz_clear( g2 ); 339 354 } 340 355 if ( deleteObject() ) delete this; 341 if ( mpz_cmp_si( &d, 1 ) == 0 )342 { 343 mpz_clear( &d );344 if ( mpz_is_imm( &n ) )345 { 346 InternalCF * res = int2imm( mpz_get_si( &n ) );347 mpz_clear( &n );356 if ( mpz_cmp_si( d, 1 ) == 0 ) 357 { 358 mpz_clear( d ); 359 if ( mpz_is_imm( n ) ) 360 { 361 InternalCF * res = int2imm( mpz_get_si( n ) ); 362 mpz_clear( n ); 348 363 return res; 349 364 } … … 368 383 else 369 384 { 370 MP_INTn, d;371 MP_INTg1, g2, tmp1, tmp2;372 mpz_init( &n ); mpz_init( &d );373 mpz_init( &g1 ); mpz_init( &g2 );374 mpz_gcd( &g1, &_num, &MPQNUM( c ) );375 mpz_gcd( &g2, &_den, &MPQDEN( c ) );376 bool g1is1 = mpz_cmp_si( &g1, 1 ) == 0;377 bool g2is1 = mpz_cmp_si( &g2, 1 ) == 0;378 mpz_init( &tmp1 ); mpz_init( &tmp2 );385 mpz_t n, d; 386 mpz_t g1, g2, tmp1, tmp2; 387 mpz_init( n ); mpz_init( d ); 388 mpz_init( g1 ); mpz_init( g2 ); 389 mpz_gcd( g1, _num, MPQNUM( c ) ); 390 mpz_gcd( g2, _den, MPQDEN( c ) ); 391 bool g1is1 = mpz_cmp_si( g1, 1 ) == 0; 392 bool g2is1 = mpz_cmp_si( g2, 1 ) == 0; 393 mpz_init( tmp1 ); mpz_init( tmp2 ); 379 394 if ( ! g1is1 ) 380 mpz_divexact( &tmp1, &_num, &g1 );381 else 382 mpz_set( &tmp1, &_num );395 mpz_divexact( tmp1, _num, g1 ); 396 else 397 mpz_set( tmp1, _num ); 383 398 if ( ! g2is1 ) 384 mpz_divexact( &tmp2, &MPQDEN( c ), &g2 );385 else 386 mpz_set( &tmp2, &MPQDEN( c ) );387 mpz_mul( &n, &tmp1, &tmp2 );399 mpz_divexact( tmp2, MPQDEN( c ), g2 ); 400 else 401 mpz_set( tmp2, MPQDEN( c ) ); 402 mpz_mul( n, tmp1, tmp2 ); 388 403 if ( ! g1is1 ) 389 mpz_divexact( &tmp1, &MPQNUM( c ), &g1 );390 else 391 mpz_set( &tmp1, &MPQNUM( c ) );404 mpz_divexact( tmp1, MPQNUM( c ), g1 ); 405 else 406 mpz_set( tmp1, MPQNUM( c ) ); 392 407 if ( ! g2is1 ) 393 mpz_divexact( &tmp2, &_den, &g2 );394 else 395 mpz_set( &tmp2, &_den );396 mpz_mul( &d, &tmp1, &tmp2 );397 mpz_clear( &tmp1 ); mpz_clear( &tmp2 );398 mpz_clear( &g1 ); mpz_clear( &g2 );408 mpz_divexact( tmp2, _den, g2 ); 409 else 410 mpz_set( tmp2, _den ); 411 mpz_mul( d, tmp1, tmp2 ); 412 mpz_clear( tmp1 ); mpz_clear( tmp2 ); 413 mpz_clear( g1 ); mpz_clear( g2 ); 399 414 if ( deleteObject() ) delete this; 400 if ( mpz_cmp_si( &d, 0 ) < 0 )401 { 402 mpz_neg( &d, &d );403 mpz_neg( &n, &n );404 } 405 if ( mpz_cmp_si( &d, 1 ) == 0 )406 { 407 mpz_clear( &d );408 if ( mpz_is_imm( &n ) )415 if ( mpz_cmp_si( d, 0 ) < 0 ) 416 { 417 mpz_neg( d, d ); 418 mpz_neg( n, n ); 419 } 420 if ( mpz_cmp_si( d, 1 ) == 0 ) 421 { 422 mpz_clear( d ); 423 if ( mpz_is_imm( n ) ) 409 424 { 410 InternalCF * res = int2imm( mpz_get_si( &n ) );411 mpz_clear( &n );425 InternalCF * res = int2imm( mpz_get_si( n ) ); 426 mpz_clear( n ); 412 427 return res; 413 428 } … … 473 488 { 474 489 ASSERT( ! ::is_imm( c ) && c->levelcoeff() == RationalDomain, "incompatible base coefficients" ); 475 MP_INTdummy1, dummy2;476 mpz_init( &dummy1 ); mpz_init( &dummy2 );477 mpz_mul( &dummy1, &_num, &MPQDEN( c ) );478 mpz_mul( &dummy2, &_den, &MPQNUM( c ) );479 int result = mpz_cmp( &dummy1, &dummy2 );480 mpz_clear( &dummy1 ); mpz_clear( &dummy2 );490 mpz_t dummy1, dummy2; 491 mpz_init( dummy1 ); mpz_init( dummy2 ); 492 mpz_mul( dummy1, _num, MPQDEN( c ) ); 493 mpz_mul( dummy2, _den, MPQNUM( c ) ); 494 int result = mpz_cmp( dummy1, dummy2 ); 495 mpz_clear( dummy1 ); mpz_clear( dummy2 ); 481 496 return result; 482 497 } … … 488 503 { 489 504 ASSERT( ::is_imm( c ) == INTMARK, "incompatible base coefficients" ); 490 MP_INTdummy;491 mpz_init_set_si( &dummy, imm2int( c ) );492 mpz_mul( &dummy, &dummy, &_den );493 int result = mpz_cmp( &_num, &dummy );494 mpz_clear( &dummy );505 mpz_t dummy; 506 mpz_init_set_si( dummy, imm2int( c ) ); 507 mpz_mul( dummy, dummy, _den ); 508 int result = mpz_cmp( _num, dummy ); 509 mpz_clear( dummy ); 495 510 return result; 496 511 } … … 498 513 { 499 514 ASSERT( c->levelcoeff() == IntegerDomain, "incompatible base coefficients" ); 500 MP_INTdummy;501 mpz_init( &dummy );502 mpz_mul( &dummy, &_den, &InternalInteger::MPI( c ) );503 int result = mpz_cmp( &_num, &dummy );504 mpz_clear( &dummy );515 mpz_t dummy; 516 mpz_init( dummy ); 517 mpz_mul( dummy, _den, InternalInteger::MPI( c ) ); 518 int result = mpz_cmp( _num, dummy ); 519 mpz_clear( dummy ); 505 520 return result; 506 521 } … … 511 526 { 512 527 ASSERT( ::is_imm( c ) == INTMARK || ! ::is_imm( c ), "expected integer" ); 513 MP_INTn, d;528 mpz_t n, d; 514 529 if ( ::is_imm( c ) ) 515 530 { … … 519 534 else 520 535 { 521 mpz_init( &n );536 mpz_init( n ); 522 537 if ( cc < 0 ) 523 538 { 524 mpz_mul_ui( &n, &_den, -cc );525 mpz_sub( &n, &_num, &n );539 mpz_mul_ui( n, _den, -cc ); 540 mpz_sub( n, _num, n ); 526 541 } 527 542 else 528 543 { 529 mpz_mul_ui( &n, &_den, cc );530 mpz_add( &n, &_num, &n );544 mpz_mul_ui( n, _den, cc ); 545 mpz_add( n, _num, n ); 531 546 } 532 547 } … … 535 550 { 536 551 ASSERT( c->levelcoeff() == IntegerDomain, "expected integer" ); 537 mpz_init( &n );538 mpz_mul( &n, &_den, &InternalInteger::MPI( c ) );539 mpz_add( &n, &_num, &n );540 } 541 mpz_init_set( &d, &_den );552 mpz_init( n ); 553 mpz_mul( n, _den, InternalInteger::MPI( c ) ); 554 mpz_add( n, _num, n ); 555 } 556 mpz_init_set( d, _den ); 542 557 // at this point there is no way that the result is not a true rational 543 558 if ( deleteObject() ) delete this; … … 548 563 { 549 564 ASSERT( ::is_imm( c ) == INTMARK || ! ::is_imm( c ), "expected integer" ); 550 MP_INTn, d;565 mpz_t n, d; 551 566 if ( ::is_imm( c ) ) 552 567 { … … 558 573 if ( getRefCount() == 1 ) 559 574 { 560 mpz_neg( &_num, &_num );575 mpz_neg( _num, _num ); 561 576 return this; 562 577 } … … 564 579 { 565 580 decRefCount(); 566 mpz_init_set( &d, &_den );567 mpz_init_set( &n, &_num );568 mpz_neg( &n, &n );581 mpz_init_set( d, _den ); 582 mpz_init_set( n, _num ); 583 mpz_neg( n, n ); 569 584 return new InternalRational( n, d ); 570 585 } … … 573 588 return this; 574 589 } 575 mpz_init( &n );590 mpz_init( n ); 576 591 if ( cc < 0 ) 577 592 { 578 mpz_mul_ui( &n, &_den, -cc );579 mpz_neg( &n, &n );580 } 581 else 582 mpz_mul_ui( &n, &_den, cc );593 mpz_mul_ui( n, _den, -cc ); 594 mpz_neg( n, n ); 595 } 596 else 597 mpz_mul_ui( n, _den, cc ); 583 598 if ( negate ) 584 mpz_sub( &n, &n, &_num );585 else 586 mpz_sub( &n, &_num, &n );599 mpz_sub( n, n, _num ); 600 else 601 mpz_sub( n, _num, n ); 587 602 } 588 603 else 589 604 { 590 605 ASSERT( c->levelcoeff() == IntegerDomain, "expected integer" ); 591 mpz_init( &n );592 mpz_mul( &n, &_den, &InternalInteger::MPI( c ) );606 mpz_init( n ); 607 mpz_mul( n, _den, InternalInteger::MPI( c ) ); 593 608 if ( negate ) 594 mpz_sub( &n, &n, &_num );595 else 596 mpz_sub( &n, &_num, &n );597 } 598 mpz_init_set( &d, &_den );609 mpz_sub( n, n, _num ); 610 else 611 mpz_sub( n, _num, n ); 612 } 613 mpz_init_set( d, _den ); 599 614 // at this point there is no way that the result is not a true rational 600 615 if ( deleteObject() ) delete this; … … 605 620 { 606 621 ASSERT( ::is_imm( c ) == INTMARK || ! ::is_imm( c ), "expected integer" ); 607 MP_INTn, d, g;622 mpz_t n, d, g; 608 623 if ( ::is_imm( c ) ) 609 624 { … … 614 629 return CFFactory::basic( 0 ); 615 630 } 616 mpz_init_set_si( &n, cc );631 mpz_init_set_si( n, cc ); 617 632 } 618 633 else 619 634 { 620 635 ASSERT( c->levelcoeff() == IntegerDomain, "expected integer" ); 621 mpz_init_set( &n, &InternalInteger::MPI( c ) );622 } 623 mpz_init( &g );624 mpz_gcd( &g, &n, &_den );625 if ( mpz_cmp_si( &g, 1 ) == 0 )626 { 627 mpz_mul( &n, &n, &_num );628 mpz_init_set( &d, &_den );629 } 630 else 631 { 632 mpz_divexact( &n, &n, &g );633 mpz_mul( &n, &n, &_num );634 mpz_init( &d );635 mpz_divexact( &d, &_den, &g );636 } 637 mpz_clear( &g );636 mpz_init_set( n, InternalInteger::MPI( c ) ); 637 } 638 mpz_init( g ); 639 mpz_gcd( g, n, _den ); 640 if ( mpz_cmp_si( g, 1 ) == 0 ) 641 { 642 mpz_mul( n, n, _num ); 643 mpz_init_set( d, _den ); 644 } 645 else 646 { 647 mpz_divexact( n, n, g ); 648 mpz_mul( n, n, _num ); 649 mpz_init( d ); 650 mpz_divexact( d, _den, g ); 651 } 652 mpz_clear( g ); 638 653 if ( deleteObject() ) delete this; 639 if ( mpz_cmp_si( &d, 1 ) == 0 )640 { 641 mpz_clear( &d );642 if ( mpz_is_imm( &n ) )643 { 644 InternalCF * res = int2imm( mpz_get_si( &n ) );645 mpz_clear( &n );654 if ( mpz_cmp_si( d, 1 ) == 0 ) 655 { 656 mpz_clear( d ); 657 if ( mpz_is_imm( n ) ) 658 { 659 InternalCF * res = int2imm( mpz_get_si( n ) ); 660 mpz_clear( n ); 646 661 return res; 647 662 } … … 658 673 { 659 674 ASSERT( ::is_imm( c ) == INTMARK || ! ::is_imm( c ), "expected integer" ); 660 MP_INTn, d, g;675 mpz_t n, d, g; 661 676 if ( ::is_imm( c ) ) 662 677 { … … 671 686 if ( invert ) 672 687 { 673 mpz_init_set_si( &n, cc );674 mpz_mul( &n, &n, &_den );675 mpz_init_set( &d, &_num );676 } 677 else 678 { 679 mpz_init_set_si( &d, cc );680 mpz_mul( &d, &d, &_den );681 mpz_init_set( &n, &_num );688 mpz_init_set_si( n, cc ); 689 mpz_mul( n, n, _den ); 690 mpz_init_set( d, _num ); 691 } 692 else 693 { 694 mpz_init_set_si( d, cc ); 695 mpz_mul( d, d, _den ); 696 mpz_init_set( n, _num ); 682 697 } 683 698 } … … 687 702 if ( invert ) 688 703 { 689 mpz_init_set( &n, &InternalInteger::MPI( c ) );690 mpz_mul( &n, &n, &_den );691 mpz_init_set( &d, &_num );692 } 693 else 694 { 695 mpz_init_set( &d, &InternalInteger::MPI( c ) );696 mpz_mul( &d, &d, &_den );697 mpz_init_set( &n, &_num );698 } 699 } 700 if ( mpz_cmp_si( &d, 0 ) < 0 )701 { 702 mpz_neg( &d, &d );703 mpz_neg( &n, &n );704 } 705 mpz_init( &g );706 mpz_gcd( &g, &n, &d );707 if ( mpz_cmp_si( &g, 1 ) != 0 )708 { 709 mpz_divexact( &d, &d, &g );710 mpz_divexact( &n, &n, &g );711 } 712 mpz_clear( &g );704 mpz_init_set( n, InternalInteger::MPI( c ) ); 705 mpz_mul( n, n, _den ); 706 mpz_init_set( d, _num ); 707 } 708 else 709 { 710 mpz_init_set( d, InternalInteger::MPI( c ) ); 711 mpz_mul( d, d, _den ); 712 mpz_init_set( n, _num ); 713 } 714 } 715 if ( mpz_cmp_si( d, 0 ) < 0 ) 716 { 717 mpz_neg( d, d ); 718 mpz_neg( n, n ); 719 } 720 mpz_init( g ); 721 mpz_gcd( g, n, d ); 722 if ( mpz_cmp_si( g, 1 ) != 0 ) 723 { 724 mpz_divexact( d, d, g ); 725 mpz_divexact( n, n, g ); 726 } 727 mpz_clear( g ); 713 728 if ( deleteObject() ) delete this; 714 729 if ( ! invert ) … … 717 732 return new InternalRational( n, d ); 718 733 } 719 if ( mpz_cmp_si( &d, 1 ) == 0 )720 { 721 mpz_clear( &d );722 if ( mpz_is_imm( &n ) )723 { 724 InternalCF * res = int2imm( mpz_get_si( &n ) );725 mpz_clear( &n );734 if ( mpz_cmp_si( d, 1 ) == 0 ) 735 { 736 mpz_clear( d ); 737 if ( mpz_is_imm( n ) ) 738 { 739 InternalCF * res = int2imm( mpz_get_si( n ) ); 740 mpz_clear( n ); 726 741 return res; 727 742 } … … 801 816 { 802 817 ASSERT( getRefCount() == 1, "illegal operation" ); 803 MP_INTg;804 mpz_init( &g );805 mpz_gcd( &g, &_num, &_den );806 if ( mpz_cmp_si( &g, 1 ) != 0 )807 { 808 mpz_divexact( &_num, &_num, &g );809 mpz_divexact( &_den, &_den, &g );818 mpz_t g; 819 mpz_init( g ); 820 mpz_gcd( g, _num, _den ); 821 if ( mpz_cmp_si( g, 1 ) != 0 ) 822 { 823 mpz_divexact( _num, _num, g ); 824 mpz_divexact( _den, _den, g ); 810 825 } 811 826 // Hier brauchen wir ein mpz_clear, J.M. 812 mpz_clear( &g );813 if ( mpz_cmp_si( &_den, 0 ) < 0 )814 { 815 mpz_neg( &_num, &_num );816 mpz_neg( &_den, &_den );817 } 818 if ( mpz_cmp_si( &_den, 1 ) == 0 )819 { 820 if ( mpz_is_imm( &_num ) )821 { 822 InternalCF * res = int2imm( mpz_get_si( &_num ) );827 mpz_clear( g ); 828 if ( mpz_cmp_si( _den, 0 ) < 0 ) 829 { 830 mpz_neg( _num, _num ); 831 mpz_neg( _den, _den ); 832 } 833 if ( mpz_cmp_si( _den, 1 ) == 0 ) 834 { 835 if ( mpz_is_imm( _num ) ) 836 { 837 InternalCF * res = int2imm( mpz_get_si( _num ) ); 823 838 delete this; 824 839 return res; … … 826 841 else 827 842 { 828 MP_INTres;829 mpz_init_set( &res, &_num );843 mpz_t res; 844 mpz_init_set( res, _num ); 830 845 delete this; 831 846 return new InternalInteger( res ); … … 839 854 int InternalRational::intval() const 840 855 { 841 ASSERT( mpz_cmp_si( &_den, 1 ) == 0, "illegal operation" );842 return (int)mpz_get_si( &_num );856 ASSERT( mpz_cmp_si( _den, 1 ) == 0, "illegal operation" ); 857 return (int)mpz_get_si( _num ); 843 858 } 844 859 … … 848 863 InternalRational::sign () const 849 864 { 850 return mpz_sgn( &_num );865 return mpz_sgn( _num ); 851 866 } 852 867 //}}} -
factory/int_rat.h
r1c48503 ra52291 27 27 { 28 28 private: 29 MP_INT_num;30 MP_INT_den;29 mpz_t _num; 30 mpz_t _den; 31 31 static int initialized; 32 static MP_INT &MPQNUM( const InternalCF * const c );33 static MP_INT &MPQDEN( const InternalCF * const c );34 static void normalize( const MP_INT &, const MP_INT &, MP_INT &, MP_INT &);32 static mpz_ptr MPQNUM( const InternalCF * const c ); 33 static mpz_ptr MPQDEN( const InternalCF * const c ); 34 static void normalize( const mpz_ptr, const mpz_ptr, mpz_ptr, mpz_ptr ); 35 35 public: 36 36 InternalRational(); … … 42 42 InternalRational( const int n, const int d ); 43 43 InternalRational( const char * str ); 44 InternalRational( const MP_INT &);45 InternalRational( const MP_INT &, const MP_INT &);44 InternalRational( const mpz_ptr ); 45 InternalRational( const mpz_ptr , const mpz_ptr ); 46 46 ~InternalRational(); 47 47 InternalCF* deepCopyObject() const; … … 100 100 friend void gmp_numerator ( const CanonicalForm & f, mpz_ptr result ); 101 101 friend void gmp_denominator ( const CanonicalForm & f, mpz_ptr result ); 102 friend CanonicalForm make_cf ( const MP_INT & n, const MP_INT &d );102 friend CanonicalForm make_cf ( const mpz_ptr n, const mpz_ptr d ); 103 103 }; 104 104 105 inline MP_INT &InternalRational::MPQNUM( const InternalCF * const c )105 inline mpz_ptr InternalRational::MPQNUM( const InternalCF * const c ) 106 106 { 107 107 return (((InternalRational*)c)->_num); 108 108 } 109 109 110 inline MP_INT &InternalRational::MPQDEN( const InternalCF * const c )110 inline mpz_ptr InternalRational::MPQDEN( const InternalCF * const c ) 111 111 { 112 112 return (((InternalRational*)c)->_den); -
factory/singext.cc
r1c48503 ra52291 23 23 if ( ff->levelcoeff() == IntegerDomain ) 24 24 { 25 mpz_init_set( result, &(InternalInteger::MPI( ff )) );25 mpz_init_set( result, (InternalInteger::MPI( ff )) ); 26 26 ff->deleteObject(); 27 27 } 28 28 else if ( ff->levelcoeff() == RationalDomain ) 29 29 { 30 mpz_init_set( result, &(InternalRational::MPQNUM( ff )) );30 mpz_init_set( result, (InternalRational::MPQNUM( ff )) ); 31 31 ff->deleteObject(); 32 32 } … … 48 48 else if ( ff->levelcoeff() == RationalDomain ) 49 49 { 50 mpz_init_set( result, &(InternalRational::MPQDEN( ff )) );50 mpz_init_set( result, (InternalRational::MPQDEN( ff )) ); 51 51 ff->deleteObject(); 52 52 } … … 64 64 65 65 CanonicalForm 66 make_cf ( const MP_INT &n )66 make_cf ( const mpz_ptr n ) 67 67 { 68 68 return CanonicalForm( CFFactory::basic( n ) ); … … 70 70 71 71 CanonicalForm 72 make_cf ( const MP_INT & n, const MP_INT &d, bool normalize )72 make_cf ( const mpz_ptr n, const mpz_ptr d, bool normalize ) 73 73 { 74 74 return CanonicalForm( CFFactory::rational( n, d, normalize ) ); -
factory/singext.h
r1c48503 ra52291 18 18 int gf_value (const CanonicalForm & f ); 19 19 20 CanonicalForm make_cf ( const MP_INT &n );20 CanonicalForm make_cf ( const mpz_ptr n ); 21 21 22 CanonicalForm make_cf ( const MP_INT & n, const MP_INT &d, bool normalize );22 CanonicalForm make_cf ( const mpz_ptr n, const mpz_ptr d, bool normalize ); 23 23 24 24 CanonicalForm make_cf_from_gf ( const int z ); -
factory/winnt/factory.h
r1c48503 ra52291 971 971 972 972 973 MP_INTgmp_numerator ( const CanonicalForm & f );974 975 MP_INTgmp_denominator ( const CanonicalForm & f );973 mpz_ptr gmp_numerator ( const CanonicalForm & f ); 974 975 mpz_ptr gmp_denominator ( const CanonicalForm & f ); 976 976 977 977 int gf_value (const CanonicalForm & f ); 978 978 979 CanonicalForm make_cf ( const MP_INT &n );980 981 CanonicalForm make_cf ( const MP_INT & n, const MP_INT &d, bool normalize );979 CanonicalForm make_cf ( const mpz_ptr n ); 980 981 CanonicalForm make_cf ( const mpz_ptr n, const mpz_ptr d, bool normalize ); 982 982 983 983 CanonicalForm make_cf_from_gf ( const int z );
Note: See TracChangeset
for help on using the changeset viewer.