------------------------------------------------------------------ */ decGetDigits -- count digits in a Units array */ / uar is the Unit array holding the number (this is often an */ accumulator of some sort) */ len is the length of the array in units [>=1] */ / returns the number of (significant) digits in the array
| 7763 | /* ------------------------------------------------------------------ */ |
| 7764 | // This may be called twice during some operations. |
| 7765 | static Int decGetDigits(Unit *uar, Int len) { |
| 7766 | Unit *up=uar+(len-1); // -> msu |
| 7767 | Int digits=(len-1)*DECDPUN+1; // possible digits excluding msu |
| 7768 | #if DECDPUN>4 |
| 7769 | uInt const *pow; // work |
| 7770 | #endif |
| 7771 | // (at least 1 in final msu) |
| 7772 | #if DECCHECK |
| 7773 | if (len<1) printf("decGetDigits called with len<1 [%ld]\n", (LI)len); |
| 7774 | #endif |
| 7775 | |
| 7776 | for (; up>=uar; up--) { |
| 7777 | if (*up==0) { // unit is all 0s |
| 7778 | if (digits==1) break; // a zero has one digit |
| 7779 | digits-=DECDPUN; // adjust for 0 unit |
| 7780 | continue;} |
| 7781 | // found the first (most significant) non-zero Unit |
| 7782 | #if DECDPUN>1 // not done yet |
| 7783 | if (*up<10) break; // is 1-9 |
| 7784 | digits++; |
| 7785 | #if DECDPUN>2 // not done yet |
| 7786 | if (*up<100) break; // is 10-99 |
| 7787 | digits++; |
| 7788 | #if DECDPUN>3 // not done yet |
| 7789 | if (*up<1000) break; // is 100-999 |
| 7790 | digits++; |
| 7791 | #if DECDPUN>4 // count the rest ... |
| 7792 | for (pow=&powers[4]; *up>=*pow; pow++) digits++; |
| 7793 | #endif |
| 7794 | #endif |
| 7795 | #endif |
| 7796 | #endif |
| 7797 | break; |
| 7798 | } // up |
| 7799 | return digits; |
| 7800 | } // decGetDigits |
| 7801 | |
| 7802 | #if DECTRACE | DECCHECK |
| 7803 | /* ------------------------------------------------------------------ */ |
no outgoing calls
no test coverage detected