Changeset bf29a4 in git
- Timestamp:
- Dec 21, 2000, 2:22:01 PM (22 years ago)
- Branches:
- (u'spielwiese', '0d6b7fcd9813a1ca1ed4220cfa2b104b97a0a003')
- Children:
- 5dab69d5a393466d9560045523c22692fb9c1323
- Parents:
- bfbc32c19cef318430013cfd78dc6aa9af738067
- Location:
- Singular
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/longrat.cc
rbfbc32 rbf29a4 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: longrat.cc,v 1.3 4 2000-12-15 18:49:32 SingularExp $ */4 /* $Id: longrat.cc,v 1.35 2000-12-21 13:22:00 pohl Exp $ */ 5 5 /* 6 6 * ABSTRACT: computation with long rational numbers (Hubert Grassmann) … … 121 121 } 122 122 123 //static number nlMapLongR(number from);123 static number nlMapLongR(number from); 124 124 static number nlMapR(number from); 125 125 … … 139 139 return nlMapR; 140 140 } 141 // if (rField_is_long_R(r)) 142 // { 143 // nMap = nlMapLongR; /* long R -> Q */ 144 // return TRUE; 145 // } 141 if (rField_is_long_R(src)) 142 { 143 return nlMapLongR; /* long R -> Q */ 144 } 146 145 return NULL; 147 146 } … … 279 278 nlNormalize(r); 280 279 return r; 280 } 281 282 static number nlMapLongR(number from) 283 { 284 gmp_float *ff=(gmp_float*)from; 285 mpf_t *f=ff->_mpfp(); 286 number res; 287 lint *dest,*ndest; 288 int size, i,negative; 289 int e,al,bl; 290 mp_ptr qp,dd,nn; 291 292 size = (*f)[0]._mp_size; 293 if (size == 0) 294 return nlInit(0); 295 if(size<0) 296 { 297 negative = 1; 298 size = -size; 299 } 300 else 301 negative = 0; 302 303 qp = (*f)[0]._mp_d; 304 while(qp[0]==0) 305 { 306 qp++; 307 size--; 308 } 309 310 e=(*f)[0]._mp_exp-size; 311 res = (number)omAllocBin(rnumber_bin); 312 #if defined(LDEBUG) 313 res->debug=123456; 314 #endif 315 dest = &(res->z); 316 317 if (e<0) 318 { 319 al = dest->_mp_size = size; 320 if (al<2) al = 2; 321 dd = (mp_ptr)omAlloc(sizeof(mp_limb_t)*al); 322 for (i=0;i<size;i++) dd[i] = qp[i]; 323 bl = 1-e; 324 nn = (mp_ptr)omAlloc(sizeof(mp_limb_t)*bl); 325 nn[bl-1] = 1; 326 for (i=bl-2;i>=0;i--) nn[i] = 0; 327 ndest = &(res->n); 328 ndest->_mp_d = nn; 329 ndest->_mp_alloc = ndest->_mp_size = bl; 330 res->s = 0; 331 } 332 else 333 { 334 al = dest->_mp_size = size+e; 335 if (al<2) al = 2; 336 dd = (mp_ptr)omAlloc(sizeof(mp_limb_t)*al); 337 for (i=0;i<size;i++) dd[i+e] = qp[i]; 338 for (i=0;i<e;i++) dd[i] = 0; 339 res->s = 3; 340 } 341 342 dest->_mp_d = dd; 343 dest->_mp_alloc = al; 344 if (negative) dest->_mp_size = -dest->_mp_size; 345 346 if (res->s==0) 347 nlNormalize(res); 348 else if (mpz_size1(&res->z)<=MP_SMALL) 349 { 350 int ui=(int)mpz_get_si(&res->z); 351 if ((((ui<<3)>>3)==ui) 352 && (mpz_cmp_si(&res->z,(long)ui)==0)) 353 { 354 mpz_clear(&res->z); 355 omFreeBin((ADDRESS)res, rnumber_bin); 356 return INT_TO_SR(ui); 357 } 358 } 359 #if defined(LDEBUG) 360 nlTest(res); 361 #endif 362 return res; 281 363 } 282 364 -
Singular/modulop.cc
rbfbc32 rbf29a4 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: modulop.cc,v 1.2 3 2000-12-15 18:49:34 SingularExp $ */4 /* $Id: modulop.cc,v 1.24 2000-12-21 13:22:01 pohl Exp $ */ 5 5 /* 6 6 * ABSTRACT: numbers modulo p (<=32003) … … 15 15 #include "numbers.h" 16 16 #include "longrat.h" 17 #include "mpr_complex.h" 17 18 #include "ring.h" 18 19 #include "modulop.h" … … 289 290 } 290 291 291 292 292 #ifdef LDEBUG 293 293 BOOLEAN npDBTest (number a, char *f, int l) … … 316 316 i%=npPrimeM; 317 317 return (number)i; 318 } 319 320 static number npMapLongR(number from) 321 { 322 gmp_float *ff=(gmp_float*)from; 323 mpf_t *f=ff->_mpfp(); 324 number res; 325 lint *dest,*ndest; 326 int size,i; 327 int e,al,bl,iz,in; 328 mp_ptr qp,dd,nn; 329 330 size = (*f)[0]._mp_size; 331 if (size == 0) 332 return npInit(0); 333 if(size<0) 334 size = -size; 335 336 qp = (*f)[0]._mp_d; 337 while(qp[0]==0) 338 { 339 qp++; 340 size--; 341 } 342 343 if(npPrimeM>2) 344 e=(*f)[0]._mp_exp-size; 345 else 346 e=0; 347 res = (number)omAllocBin(rnumber_bin); 348 #if defined(LDEBUG) 349 res->debug=123456; 350 #endif 351 dest = &(res->z); 352 353 if (e<0) 354 { 355 al = dest->_mp_size = size; 356 if (al<2) al = 2; 357 dd = (mp_ptr)omAlloc(sizeof(mp_limb_t)*al); 358 for (i=0;i<size;i++) dd[i] = qp[i]; 359 bl = 1-e; 360 nn = (mp_ptr)omAlloc(sizeof(mp_limb_t)*bl); 361 nn[bl-1] = 1; 362 for (i=bl-2;i>=0;i--) nn[i] = 0; 363 ndest = &(res->n); 364 ndest->_mp_d = nn; 365 ndest->_mp_alloc = ndest->_mp_size = bl; 366 res->s = 0; 367 in=mpz_mmod_ui(NULL,ndest,npPrimeM); 368 mpz_clear(ndest); 369 } 370 else 371 { 372 al = dest->_mp_size = size+e; 373 if (al<2) al = 2; 374 dd = (mp_ptr)omAlloc(sizeof(mp_limb_t)*al); 375 for (i=0;i<size;i++) dd[i+e] = qp[i]; 376 for (i=0;i<e;i++) dd[i] = 0; 377 res->s = 3; 378 } 379 380 dest->_mp_d = dd; 381 dest->_mp_alloc = al; 382 iz=mpz_mmod_ui(NULL,dest,npPrimeM); 383 mpz_clear(dest); 384 omFreeBin((ADDRESS)res, rnumber_bin); 385 if(res->s==0) 386 iz=(int)npDiv((number)iz,(number)in); 387 return (number)iz; 318 388 } 319 389 … … 336 406 } 337 407 } 408 if (rField_is_long_R(src)) 409 { 410 return npMapLongR; 411 } 338 412 return NULL; /* default */ 339 413 }
Note: See TracChangeset
for help on using the changeset viewer.