Changeset 236a4c in git
- Timestamp:
- Feb 19, 2013, 5:54:48 PM (10 years ago)
- Branches:
- (u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'f875bbaccd0831e36aaed09ff6adeb3eb45aeb94')
- Children:
- 3693cf538753b44f4862e8f7dc384771128b32d0
- Parents:
- a81ddb0212ef423502e854619e48d78e1477e806
- git-author:
- Yue Ren <ren@mathematik.uni-kl.de>2013-02-19 17:54:48+01:00
- git-committer:
- Yue Ren <ren@mathematik.uni-kl.de>2013-02-19 20:07:24+01:00
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libpolys/coeffs/shortfl.cc
ra81ddb r236a4c 6 6 * ABSTRACT: 7 7 */ 8 8 #include <iostream> 9 9 #include <coeffs/shortfl.h> 10 10 11 11 #include <string.h> 12 #include <math.h> 12 13 #include <coeffs/coeffs.h> 13 14 #include <coeffs/numbers.h> … … 373 374 assume( getCoeffType(r) == ID ); 374 375 assume( getCoeffType(aRing) == n_Zp ); 375 376 376 377 int i = (int)((long)from); 377 378 float f = (float)i; … … 389 390 390 391 static number nrMapC(number from, const coeffs aRing, const coeffs r) 391 { 392 { 392 393 assume( getCoeffType(r) == ID ); 393 394 assume( getCoeffType(aRing) == n_long_C ); 394 395 395 396 gmp_float h = ((gmp_complex*)from)->real(); 396 397 float t =(float)mpf_get_d((mpf_srcptr)&h); … … 406 407 */ 407 408 #define SR_HDL(A) ((long)(A)) 408 #define mpz_isNeg(A) ((A)->_mp_size<0)409 #define mpz_limb_size(A) ((A)->_mp_size)410 #define mpz_limb_d(A) ((A)->_mp_d)411 #define MPZ_DIV(A,B,C) mpz_tdiv_q((A),(B),(C))412 409 #define IS_INT(A) ((A)->s==3) 413 410 #define IS_IMM(A) (SR_HDL(A)&SR_INT) 414 411 #define GET_NOM(A) ((A)->z) 415 412 #define GET_DENOM(A) ((A)->n) 416 #define MPZ_INIT mpz_init417 #define MPZ_CLEAR mpz_clear418 413 419 414 assume( getCoeffType(r) == ID ); 420 415 assume( getCoeffType(aRing) == n_Q ); 421 422 mpz_t h;423 mpz_ptr g,z,n;424 int i,j,t,s;425 float ba,rr,rn,y;426 416 427 417 if (IS_IMM(from)) 428 418 return nf((float)nlInt(from,NULL /* dummy for nlInt*/)).N(); 429 z=GET_NOM(from); 430 s=0X10000; 431 ba=(float)s; 432 ba*=ba; 433 rr=0.0; 434 i=mpz_size1(z); 419 420 /* read out the enumerator */ 421 mpz_ptr z=GET_NOM(from); 422 if(mpz_size1(z)>4) 423 { 424 WerrorS("float overflow"); 425 return nf(0.0).N(); 426 } 427 mpf_t e; 428 mpf_init(e); 429 mpf_set_z(e,z); 430 431 /* if number was an integer, we are done*/ 435 432 if(IS_INT(from)) 436 433 { 437 if(i>4) 438 { 439 WerrorS("float overflow"); 440 return nf(rr).N(); 441 } 442 i--; 443 rr=(float)mpz_limb_d(z)[i]; 444 while(i>0) 445 { 446 i--; 447 y=(float)mpz_limb_d(z)[i]; 448 rr=rr*ba+y; 449 } 450 if(mpz_isNeg(z)) 451 rr=-rr; 452 return nf(rr).N(); 453 } 454 n=GET_DENOM(from); 455 j=s=mpz_limb_size(n); 456 if(j>i) 457 { 458 g=n; n=z; z=g; 459 t=j; j=i; i=t; 460 } 461 t=i-j; 462 if(t>4) 463 { 464 if(j==s) 465 WerrorS("float overflow"); 466 return nf(rr).N(); 467 } 468 if(t>1) 469 { 470 g=h; 471 MPZ_INIT(g); 472 MPZ_DIV(g,z,n); 473 t=mpz_size1(g); 474 if(t>4) 475 { 476 MPZ_CLEAR(g); 477 if(j==s) 478 WerrorS("float overflow"); 479 return nf(rr).N(); 480 } 481 t--; 482 rr=(float)mpz_limb_d(g)[t]; 483 while(t) 484 { 485 t--; 486 y=(float)mpz_limb_d(g)[t]; 487 rr=rr*ba+y; 488 } 489 MPZ_CLEAR(g); 490 if(j!=s) 491 rr=1.0/rr; 492 if(mpz_isNeg(z)) 493 rr=-rr; 494 return nf(rr).N(); 495 } 496 rn=(float)mpz_limb_d(n)[j-1]; 497 rr=(float)mpz_limb_d(z)[i-1]; 498 if(j>1) 499 { 500 rn=rn*ba+(float)mpz_limb_d(n)[j-2]; 501 rr=rr*ba+(float)mpz_limb_d(z)[i-2]; 502 i--; 503 } 504 if(t!=0) 505 rr=rr*ba+(float)mpz_limb_d(z)[i-2]; 506 if(j==s) 507 rr=rr/rn; 508 else 509 rr=rn/rr; 510 if(mpz_isNeg(z)) 511 rr=-rr; 512 return nf(rr).N(); 513 } 514 434 double basis; 435 signed long int exp; 436 basis = mpf_get_d_2exp(&exp, e); 437 float f = ldexp(basis,exp); 438 mpf_clear(e); 439 return nf(f).N(); 440 } 441 442 /* else read out the denominator */ 443 mpz_ptr n = GET_DENOM(from); 444 if(mpz_size1(n)>4) 445 { 446 WerrorS("float overflow"); 447 mpf_clear(e); 448 return nf(0.0).N(); 449 } 450 mpf_t d; 451 mpf_init(d); 452 mpf_set_z(d,n); 453 454 /* and compute the quotient */ 455 mpf_t q; 456 mpf_init(q); 457 mpf_div(q,e,d); 458 459 double basis; 460 signed long int exp; 461 basis = mpf_get_d_2exp(&exp, q); 462 float f = ldexp(basis,exp); 463 mpf_clear(e); 464 mpf_clear(d); 465 mpf_clear(q); 466 return nf(f).N(); 467 } 515 468 516 469 nMapFunc nrSetMap(const coeffs src, const coeffs dst) … … 544 497 { 545 498 assume( getCoeffType(n) == ID ); 546 499 547 500 assume( p == NULL ); 548 501 549 502 n->cfKillChar = ndKillChar; /* dummy */ 550 503 n->ch = 0; … … 578 531 n->cfDBTest=ndDBTest; // not yet implemented: nrDBTest; 579 532 #endif 580 533 581 534 n->nCoeffIsEqual = ndCoeffIsEqual; 582 535 583 536 n->float_len = SHORT_REAL_LENGTH; 584 537 n->float_len2 = SHORT_REAL_LENGTH; 585 538 586 539 // TODO: Any variables? 587 540 return FALSE;
Note: See TracChangeset
for help on using the changeset viewer.