------------------------------------------------------------------ */ decFloatFromBCD -- set decFloat from exponent, BCD8, and sign */ / df is the target decFloat */ exp is the in-range unbiased exponent, q, or a special value in */ the form returned by decFloatGetExponent */ bcdar holds DECPMAX digits to set the coefficient fro
| 575 | /* No error is possible, and no status will be set. */ |
| 576 | /* ------------------------------------------------------------------ */ |
| 577 | decFloat * decFloatFromBCD(decFloat *df, Int exp, const uByte *bcdar, |
| 578 | Int sig) { |
| 579 | uInt encode, dpd; // work |
| 580 | const uByte *ub; // .. |
| 581 | |
| 582 | if (EXPISSPECIAL(exp)) encode=exp|sig;// specials already encoded |
| 583 | else { // is finite |
| 584 | // encode the combination field and exponent continuation |
| 585 | uInt uexp=(uInt)(exp+DECBIAS); // biased exponent |
| 586 | uInt code=(uexp>>DECECONL)<<4; // top two bits of exp |
| 587 | code+=bcdar[0]; // add msd |
| 588 | // look up the combination field and make high word |
| 589 | encode=DECCOMBFROM[code]|sig; // indexed by (0-2)*16+msd |
| 590 | encode|=(uexp<<(32-6-DECECONL)) & 0x03ffffff; // exponent continuation |
| 591 | } |
| 592 | |
| 593 | // private macro to extract a declet, n (where 0<=n<DECLETS and 0 |
| 594 | // refers to the declet from the least significant three digits) |
| 595 | // and put the corresponding DPD code into dpd. |
| 596 | // Use of a working pointer, uInt *ub, is assumed. |
| 597 | |
| 598 | #define getDPDb(dpd, n) ub=bcdar+DECPMAX-1-(3*(n))-2; \ |
| 599 | dpd=BCD2DPD[(*ub*256)+(*(ub+1)*16)+*(ub+2)]; |
| 600 | |
| 601 | // place the declets in the encoding words and copy to result (df), |
| 602 | // according to endianness; in all cases complete the sign word |
| 603 | // first |
| 604 | #if DECPMAX==7 |
| 605 | getDPDb(dpd, 1); |
| 606 | encode|=dpd<<10; |
| 607 | getDPDb(dpd, 0); |
| 608 | encode|=dpd; |
| 609 | DFWORD(df, 0)=encode; // just the one word |
| 610 | |
| 611 | #elif DECPMAX==16 |
| 612 | getDPDb(dpd, 4); encode|=dpd<<8; |
| 613 | getDPDb(dpd, 3); encode|=dpd>>2; |
| 614 | DFWORD(df, 0)=encode; |
| 615 | encode=dpd<<30; |
| 616 | getDPDb(dpd, 2); encode|=dpd<<20; |
| 617 | getDPDb(dpd, 1); encode|=dpd<<10; |
| 618 | getDPDb(dpd, 0); encode|=dpd; |
| 619 | DFWORD(df, 1)=encode; |
| 620 | |
| 621 | #elif DECPMAX==34 |
| 622 | getDPDb(dpd,10); encode|=dpd<<4; |
| 623 | getDPDb(dpd, 9); encode|=dpd>>6; |
| 624 | DFWORD(df, 0)=encode; |
| 625 | |
| 626 | encode=dpd<<26; |
| 627 | getDPDb(dpd, 8); encode|=dpd<<16; |
| 628 | getDPDb(dpd, 7); encode|=dpd<<6; |
| 629 | getDPDb(dpd, 6); encode|=dpd>>4; |
| 630 | DFWORD(df, 1)=encode; |
| 631 | |
| 632 | encode=dpd<<28; |
| 633 | getDPDb(dpd, 5); encode|=dpd<<18; |
| 634 | getDPDb(dpd, 4); encode|=dpd<<8; |
no outgoing calls
no test coverage detected