Lines Matching refs:digits

60 /*    precision (up to 999,999,999 digits) and arbitrary exponent     */
64 /* tightly: digits, emax, and -emin in the context must be <= */
69 /* be finite, positive, have an exponent of zero, and all digits */
70 /* must be either 0 or 1. The result will only contain digits */
150 /* 6. The digits count is allowed to rise to a multiple of DECDPUN */
152 /* accounting of digits is not needed. The correct digits value */
154 /* This must be called before any rounding if the number of digits */
158 /* numbers up to four digits, using appropriate constants. This */
321 /* complement of digits (where appropriate -- this is not the case */
372 dn->digits=decGetDigits(dn->lsu, up-dn->lsu);
391 /* special or too many digits, or bad exponent */
392 if (dn->bits&DECSPECIAL || dn->digits>10 || dn->exponent!=0) ; /* bad */
393 else { /* is a finite integer with 10 or fewer digits */
398 lo=*up; /* get 1 to 9 digits */
405 for (d=DECDPUN; d<dn->digits; up++, d+=DECDPUN) hi+=*up*powers[d-1];
426 /* special or too many digits, or bad exponent, or negative (<0) */
427 if (dn->bits&DECSPECIAL || dn->digits>10 || dn->exponent!=0
429 else { /* is a finite integer with 10 or fewer digits */
434 lo=*up; /* get 1 to 9 digits */
441 for (d=DECDPUN; d<dn->digits; up++, d+=DECDPUN) hi+=*up*powers[d-1];
461 /* string must be at least dn->digits+14 characters long */
483 /* (set.digits), determining the maximum and minimum */
503 Int d=0; /* count of digits found in decimal part */
524 d++; /* count of real digits */
544 if (last==NULL) { /* no digits yet */
585 if (*c!='\0') break; /* not all digits */
586 if (d>set->digits-1) {
588 /* clamped, in which case can only be digits-1] */
590 if (d>set->digits) break;
591 } /* too many digits? */
598 /* had some digits; exponent is only valid sequence now */
629 } /* stuff after digits */
655 /* OK, the digits string is good. Assemble in the decNumber, or in */
657 if (d<=set->digits) res=dn->lsu; /* fits into supplied decNumber */
674 cut=d-(up-res)*DECDPUN; /* digits in top unit */
675 for (c=cfirst;; c++) { /* along the digits */
700 dn->digits=d;
703 if (d>set->digits) {
711 if ((dn->exponent-1<set->emin-dn->digits)
712 || (dn->exponent-1>set->emax-set->digits)) {
739 /* C must have space for set->digits digits. */
773 /* C must have space for set->digits digits. */
797 /* C must have space for set->digits digits. */
807 Int msudigs; /* digits in res msu */
822 msua=ua+D2U(lhs->digits)-1; /* -> msu of lhs */
823 msub=ub+D2U(rhs->digits)-1; /* -> msu of rhs */
824 msuc=uc+D2U(set->digits)-1; /* -> msu of result */
825 msudigs=MSUDIGITS(set->digits); /* [faster than remainder] */
852 res->digits=decGetDigits(res->lsu, uc-res->lsu);
950 needbytes=sizeof(decNumber)+(D2U(lhs->digits)-1)*sizeof(Unit);
964 needbytes=sizeof(decNumber)+(D2U(rhs->digits)-1)*sizeof(Unit);
995 /* C must have space for set->digits digits. */
1018 /* C must have space for set->digits digits. */
1037 /* C must have space for set->digits digits. */
1072 if (rhs->digits>set->digits) {
1107 /* C must have space for set->digits digits. */
1137 dcmul.digits=lhs->digits+rhs->digits; /* just enough */
1143 needbytes=sizeof(decNumber)+(D2U(dcmul.digits)-1)*sizeof(Unit);
1195 /* C must have space for set->digits digits. */
1204 Int msudigs; /* digits in res msu */
1216 msua=ua+D2U(rhs->digits)-1; /* -> msu of rhs */
1217 msuc=uc+D2U(set->digits)-1; /* -> msu of result */
1218 msudigs=MSUDIGITS(set->digits); /* [faster than remainder] */
1239 res->digits=decGetDigits(res->lsu, uc-res->lsu);
1254 /* C must have space for set->digits digits. */
1290 if (rhs->digits>set->digits) {
1322 /* set is the context, used only for digits and status */
1324 /* C must have space for 10 digits (A might have 10**9 digits and */
1329 /* with zeros on the right to set->digits digits while keeping the */
1356 Int ae=rhs->exponent+rhs->digits-1; /* adjusted exponent */
1373 /* C must have space for set->digits digits. */
1389 /* ln(A) this is the max(p, rhs->digits + t) + 3, where p is the */
1390 /* requested digits and t is the number of digits in the exponent */
1404 Int t; /* digits in exponent of A */
1432 if (rhs->digits>set->digits) {
1452 aset.digits=1;
1469 /* number of digits in a, including exponent' as compared to the */
1470 /* requested digits, as increasing this will only rarely cost an */
1475 p=(rhs->digits+t>set->digits?rhs->digits+t:set->digits)+3;
1484 aset.digits=p; /* as calculated */
1497 /* for ln(10) an extra 3 digits of precision are needed */
1498 p=set->digits+3;
1513 w->digits=2; /* .. */
1515 aset.digits=p;
1518 aset.digits=set->digits; /* for final divide */
1548 /* C must have space for set->digits digits. */
1571 /* C must have space for set->digits digits. */
1594 /* C must have space for set->digits digits. */
1617 /* C must have space for set->digits digits. */
1640 /* C must have space for set->digits digits. */
1813 /* C must have space for set->digits digits. */
1823 Int msudigs; /* digits in res msu */
1837 msua=ua+D2U(lhs->digits)-1; /* -> msu of lhs */
1838 msub=ub+D2U(rhs->digits)-1; /* -> msu of rhs */
1839 msuc=uc+D2U(set->digits)-1; /* -> msu of result */
1840 msudigs=MSUDIGITS(set->digits); /* [faster than remainder] */
1866 res->digits=decGetDigits(res->lsu, uc-res->lsu);
1882 /* C must have space for set->digits digits. */
1916 /* C must have space for set->digits digits. */
1939 /* C must have space for set->digits digits. */
1963 Int reqdigits=set->digits; /* requested DIGITS */
1979 /* local accumulator buffer [a decNumber, with digits+elength+1 digits] */
1992 if (lhs->digits>reqdigits) {
1997 if (rhs->digits>reqdigits) {
2026 Int shift=set->digits-1;
2028 res->digits=decShiftToMost(res->lsu, 1, shift);
2114 /* is the total digits, including exponent), or the requested */
2117 /* than the requested digits as it greatly reduces the >0.5 ulp */
2118 /* cases at little cost (because Ln doubles digits each */
2119 /* iteration so a few extra digits rarely causes an extra */
2121 aset.digits=MAXI(lhs->digits, set->digits)+6+4;
2136 aset.digits=reqdigits+(rhs->digits+rhs->exponent)+2;
2138 if (!set->extended) aset.digits--; /* use classic precision */
2141 if (aset.digits>DECNUMMAXP) {status|=DEC_Invalid_operation; break;}
2144 /* aset.digits is the count of digits for the accumulator needed */
2146 needbytes=sizeof(decNumber)+(D2U(aset.digits)-1)*sizeof(Unit);
2167 Int shift=set->digits-1;
2168 dac->digits=decShiftToMost(dac->lsu, 1, shift);
2186 if (decNumberIsNegative(rhs)) { /* was a **-n [hence digits>0] */
2245 /* round subnormals [to set.digits rather than aset.digits] */
2254 decNumberIsNegative(rhs)) { /* was a **-n [hence digits>0] */
2295 /* C must have space for set->digits digits. */
2317 /* C must have space for set->digits digits. */
2342 if (rhs->digits>set->digits) {
2384 /* C must have space for set->digits digits. */
2407 /* C must have space for set->digits digits. */
2430 /* C must have space for set->digits digits. */
2446 /* This computes C = A rot B (in base ten and rotating set->digits */
2447 /* digits). */
2451 /* rhs is B, the number of digits to rotate (-ve to right) */
2454 /* The digits of the coefficient of A are rotated to the left (if B */
2456 /* the exponent or the sign of A. If lhs->digits is less than */
2457 /* set->digits the coefficient is padded with zeros on the left */
2461 /* B must be an integer (q=0) and in the range -set->digits through */
2462 /* +set->digits. */
2463 /* C must have space for set->digits digits. */
2487 || abs(rotate)>set->digits) /* .. or out of range */
2492 if (rotate<0) rotate=set->digits+rotate;
2493 if (rotate!=0 && rotate!=set->digits /* zero or full rotation */
2495 /* left-rotate to do; 0 < rotate < set->digits */
2497 uInt msudigits; /* digits in result msu */
2498 Unit *msu=res->lsu+D2U(res->digits)-1; /* current msu */
2499 Unit *msumax=res->lsu+D2U(set->digits)-1; /* rotation msu */
2501 res->digits=set->digits; /* now full-length */
2502 msudigits=MSUDIGITS(res->digits); /* actual digits in msu */
2506 /* lsd [any digits shifted out are rotated to the left, */
2514 /* digits shifted out will fit exactly in the current msu, */
2520 /* example: rotate right 8 digits (2 units + 2), DECDPUN=3. */
2535 rotate=set->digits-rotate; /* make it right-rotate */
2537 shift=rotate%DECDPUN; /* left-over digits count */
2540 decShiftToLeast(res->lsu, D2U(res->digits), shift);
2541 if (shift>msudigits) { /* msumax-1 needs >0 digits */
2550 } /* digits shift needed */
2572 res->digits=decGetDigits(res->lsu, msumax-res->lsu+1);
2613 /* maximum magnitude 2*(emax+digits) */
2620 /* C must have space for set->digits digits. */
2645 || abs(reqexp)>(2*(set->digits+set->emax))) /* .. or out of range */
2667 /* rhs is B, the number of digits to shift (-ve to right) */
2670 /* The digits of the coefficient of A are shifted to the left (if B */
2674 /* B must be an integer (q=0) and in the range -set->digits through */
2675 /* +set->digits. */
2676 /* C must have space for set->digits digits. */
2700 || abs(shift)>set->digits) /* .. or out of range */
2706 if (shift==set->digits) { /* removing all */
2708 res->digits=1; /* .. */
2711 /* first remove leading digits if necessary */
2712 if (res->digits+shift>set->digits) {
2713 decDecap(res, res->digits+shift-set->digits);
2714 /* that updated res->digits; may have gone to 1 (for a */
2717 if (res->digits>1 || *res->lsu) /* if non-zero.. */
2718 res->digits=decShiftToMost(res->lsu, res->digits, shift);
2722 if (-shift>=res->digits) { /* discarding all */
2724 res->digits=1; /* .. */
2727 decShiftToLeast(res->lsu, D2U(res->digits), -shift);
2728 res->digits-=(-shift);
2747 /* C must have space for set->digits digits. */
2843 /* buffer for temporary variable, up to 3 digits */
2855 if (rhs->digits>set->digits) {
2903 workp=MAXI(set->digits+1, rhs->digits); /* actual rounding precision */
2907 needbytes=sizeof(decNumber)+(D2U(rhs->digits)-1)*sizeof(Unit);
2929 exp=f->exponent+f->digits; /* adjusted to Hull rules */
2930 f->exponent=-(f->digits); /* to range */
2941 workset.digits=workp; /* p for initial calculation */
2942 t->bits=0; t->digits=3;
2943 a->bits=0; a->digits=3;
2987 workset.digits=3; /* initial p */
2988 for (; workset.digits<maxp;) {
2990 workset.digits=MINI(workset.digits*2-2, maxp);
2998 /* Here, 0.1 <= a < 1 [Hull], and a has maxp digits */
3027 /* Here workset.digits=maxp and t=0.5, and a->digits determines */
3029 workset.digits--; /* maxp-1 is OK now */
3030 t->exponent=-a->digits-1; /* make 0.5 ulp */
3073 /* digits, so this is the only (relatively rare) condition that */
3075 if (b->digits*2-1 > workp) { /* cannot fit */
3094 Int maxexp=set->emax-set->digits+1;
3105 decShiftToLeast(a->lsu, D2U(a->digits), todrop);
3107 a->digits-=todrop; /* new length */
3117 Int ae=rhs->exponent+rhs->digits-1; /* adjusted exponent */
3157 /* C must have space for set->digits digits. */
3188 /* the digits setting is ignored. The Exact version will signal */
3212 workset.digits=rhs->digits; /* no length rounding */
3243 /* C must have space for set->digits digits. */
3253 Int msudigs; /* digits in res msu */
3267 msua=ua+D2U(lhs->digits)-1; /* -> msu of lhs */
3268 msub=ub+D2U(rhs->digits)-1; /* -> msu of rhs */
3269 msuc=uc+D2U(set->digits)-1; /* -> msu of result */
3270 msudigs=MSUDIGITS(set->digits); /* [faster than remainder] */
3296 res->digits=decGetDigits(res->lsu, uc-res->lsu);
3380 dest->digits=src->digits;
3382 if (src->digits>DECDPUN) { /* more Units to come */
3388 smsup=src->lsu+D2U(src->digits); /* -> source msu+1 */
3402 /* C must have space for set->digits digits. */
3423 /* C must have space for set->digits digits. */
3445 /* C must have space for set->digits digits. */
3464 /* bcd is the uInt array that will receive dn->digits BCD bytes, */
3468 /* bcd must have at least dn->digits bytes. No error is possible; if */
3469 /* dn is a NaN or Infinite, digits must be 1 and the coefficient 0. */
3472 uByte *ub=bcd+dn->digits-1; /* -> lsd */
3498 /* n is the number of digits in the source BCD array (bcd) */
3501 /* dn must have space for at least n digits. No error is possible; */
3506 Unit *up=dn->lsu+D2U(dn->digits)-1; /* -> msu [target pointer] */
3512 /* calculate how many digits in msu, and hence first cut */
3515 *up=0; /* will take <=DECDPUN digits */
3517 cut=DECDPUN; /* next Unit has all digits */
3520 dn->digits=n; /* set digit count */
3539 ae=dn->exponent+dn->digits-1; /* adjusted exponent */
3559 ae=dn->exponent+dn->digits-1; /* adjusted exponent */
3610 dn->digits=1;
3626 /* string must be at least dn->digits+14 characters long */
3638 Int pre; /* digits before the '.' */
3639 Int cut; /* for counting digits in a Unit */
3641 const Unit *up=dn->lsu+D2U(dn->digits)-1; /* -> msu [input pointer] */
3668 if (exp!=0 || (*dn->lsu==0 && dn->digits==1)) return;
3672 /* calculate how many digits in msu, and hence first cut */
3673 cut=MSUDIGITS(dn->digits); /* [faster than remainder] */
3678 u=*up; /* contains DECDPUN digits to lay out */
3680 cut=DECDPUN-1; /* next Unit has all digits */
3686 pre=dn->digits+exp; /* digits before '.' */
3689 e=exp+dn->digits-1; /* calculate E value */
3716 /* lay out the digits of the coefficient, adding 0s and . as needed */
3722 if (up==dn->lsu) break; /* out of input digits (pre>digits) */
3729 if (n<dn->digits) { /* more to come, after '.' */
3733 if (up==dn->lsu) break; /* out of input digits */
3749 if (up==dn->lsu) break; /* out of input digits */
3794 /* C must have space for set->digits digits. */
3799 /* -- a digits+1 calculation is needed because the numbers are */
3800 /* unaligned and span more than set->digits digits */
3801 /* -- a carry to digits+1 digits looks possible */
3835 Int reqdigits=set->digits; /* local copy; requested DIGITS */
3846 if (lhs->digits>reqdigits) {
3851 if (rhs->digits>reqdigits) {
3907 if ((res->digits-adjust)>set->digits) {
3908 adjust=res->digits-set->digits; /* to fit exactly */
3911 res->digits=decShiftToMost(res->lsu, res->digits, -adjust);
3934 if ((res->digits-adjust)>set->digits) {
3935 adjust=res->digits-set->digits; /* to fit exactly */
3938 res->digits=decShiftToMost(res->lsu, res->digits, -adjust);
3957 && rhs->digits<=DECDPUN
3959 && rhs->exponent<=set->emax-set->digits+1 /* [could clamp] */
3960 && rhs->digits<=reqdigits
3961 && lhs->digits<=reqdigits) {
3966 && (lhs->digits>=DECDPUN || /* .. and no digits-count change */
3967 partial<(Int)powers[lhs->digits])) { /* .. */
3979 /* this could have reduced digits [but result>0] */
3980 res->digits=decGetDigits(res->lsu, D2U(res->digits));
4012 /* If, after pad, rhs would be longer than lhs by digits+1 or */
4015 if (rhs->digits+padding > lhs->digits+reqdigits+1) {
4018 Int shift=reqdigits-rhs->digits; /* left shift needed */
4025 res->digits=decShiftToMost(res->lsu, res->digits, shift);
4033 /* LHS digits may affect result */
4041 maxdigits=rhs->digits+padding; /* virtual length of RHS */
4042 if (lhs->digits>maxdigits) maxdigits=lhs->digits;
4052 /* buffer needed, choose it; units for maxdigits digits will be */
4070 decDumpAr('A', lhs->lsu, D2U(lhs->digits));
4071 decDumpAr('B', rhs->lsu, D2U(rhs->digits));
4076 res->digits=decUnitAddSub(lhs->lsu, D2U(lhs->digits),
4077 rhs->lsu, D2U(rhs->digits),
4079 *DECDPUN; /* [units -> digits] */
4080 if (res->digits<0) { /* borrowed... */
4081 res->digits=-res->digits;
4085 decDumpAr('+', acc, D2U(res->digits));
4098 if (res->digits>reqdigits)
4099 res->digits=decGetDigits(acc, D2U(res->digits));
4100 decSetCoeff(res, set, acc, res->digits, &residue, status);
4105 /* numbers fit in DECDPUN digits and are padding with a */
4109 if (res->digits<maxdigits) {
4110 *(acc+D2U(res->digits))=0; /* ensure leading 0 is there */
4111 res->digits=maxdigits;
4117 if (res->digits>reqdigits) {
4118 res->digits=decGetDigits(acc, D2U(res->digits));
4119 if (res->digits<maxdigits) res->digits=maxdigits;
4122 decSetCoeff(res, set, acc, res->digits, &residue, status);
4134 res->digits=decGetDigits(res->lsu, D2U(res->digits));
4176 /* C must have space for set->digits digits. */
4195 /* Do until (have=digits+1 OR residue=0) */
4224 /* Two working buffers are needed during the division; one (digits+ */
4225 /* 1) to accumulate the result, and the other (up to 2*digits+1) for */
4244 Int accdigits; /* count of digits accumulated */
4258 Int var1initpad=0; /* var1 initial padding (digits) */
4263 Int reqdigits=set->digits; /* requested DIGITS */
4283 if (lhs->digits>reqdigits) {
4288 if (rhs->digits>reqdigits) {
4329 res->exponent=set->emin-set->digits+1;
4386 exponent=(lhs->exponent+lhs->digits)-(rhs->exponent+rhs->digits);
4432 /* (rhs->digits+reqdigits-1) -- to allow full slide to right */
4433 /* or (lhs->digits) -- to allow for long lhs */
4439 maxdigits=rhs->digits+reqdigits-1;
4440 if (lhs->digits>maxdigits) maxdigits=lhs->digits;
4460 source=lhs->lsu+D2U(lhs->digits)-1; /* msu of input array */
4466 var2units=D2U(rhs->digits); /* rhs actual length (units) */
4484 /* [This is actually done by counting the digits and negating, as */
4496 /* save the initial 'false' padding of var1, in digits */
4497 var1initpad=(var1units-D2U(lhs->digits))*DECDPUN;
4519 accdigits=0; /* .. or digits */
4520 accnext=acc+acclength-1; /* -> msu of acc [NB: allows digits+1] */
4588 /* account exactly for the new digits */
4596 if (accdigits>reqdigits) break; /* have enough digits */
4600 /* or divideInteger and still not enough digits yet) */
4620 /* accunits is the number of digits collected in acc */
4699 /* calculate the unused zero digits. This is the smaller of: */
4706 /* shift var1 the requested amount, and adjust its digits */
4731 compare=decUnitCompare(accnext, tarunits, rhs->lsu, D2U(rhs->digits),
4764 quotdigits-=DECDPUN; /* checked those digits */
4779 rhs->lsu, D2U(rhs->digits),
4781 accdigits=decGetDigits(accnext, accunits); /* count digits exactly */
4825 /* C must have space for set->digits digits. */
4872 #define FASTDIGS 9 /* digits in base */
4937 if (lhs->digits<rhs->digits) { /* swap... */
4947 if (lhs->digits>set->digits) {
4952 if (rhs->digits>set->digits) {
4962 /* use the fast path if there are enough digits in the shorter */
4965 if (rhs->digits>NEEDTWO) { /* use fastpath... */
4967 ilhs=(lhs->digits+FASTDIGS-1)/FASTDIGS; /* [ceiling] */
4968 irhs=(rhs->digits+FASTDIGS-1)/FASTDIGS; /* .. */
5006 for (count=lhs->digits, cup=lhs->lsu, lip=zlhi; count>0; lip++)
5011 for (count=rhs->digits, cup=rhs->lsu, rip=zrhi; count>0; rip++)
5028 /* add -- every 162 digits. Similarly, when FASTDIGS=8, the */
5031 /* resolution occurs only every 14752 digits. Hence for common */
5088 needbytes=(D2U(lhs->digits)+D2U(rhs->digits))*sizeof(Unit);
5103 madlength=D2U(lhs->digits); /* this won't change */
5104 mermsup=rhs->lsu+D2U(rhs->digits); /* -> msu+1 of multiplier */
5132 res->digits=decGetDigits(acc, accunits); /* count digits exactly */
5146 decSetCoeff(res, set, acc, res->digits, &residue, status);
5171 /* C must have space for set->digits digits. status is updated but */
5176 /* digits, emax, and -emin in the context must be less than */
5258 /* the working precision will be no more than set->digits+8+1 */
5270 /* decNumber for the divisor term; this needs at most 9 digits */
5304 /* set->digits-1 zeros between the decimal point and the digit, */
5307 /* 1.0000001. Hence, tiny will be 0.0000004 if digits=7 and x>0 */
5308 /* or 0.00000004 if digits=7 and x<0. If RHS not larger than */
5312 d->exponent=-set->digits; /* * 10**(-d) */
5319 Int shift=set->digits-1;
5322 res->digits=decShiftToMost(res->lsu, 1, shift);
5337 h=rhs->exponent+rhs->digits;
5354 Int maxlever=(rhs->digits>8?1:0);
5360 /* Apply as much as possible, up to a MAXLEVER digits, which */
5363 /* increases to compensate for the "constant digits at the */
5366 Int use=-rhs->digits-lever; /* exponent to use for RHS */
5375 needbytes=sizeof(decNumber)+(D2U(rhs->digits)-1)*sizeof(Unit);
5395 /* this is set->digits+h+2. However, if x is 'over-precise' we */
5396 /* need to allow for all its digits to potentially participate */
5397 /* (consider an x where all the excess digits are 9s) so in */
5398 /* this case use x->digits+h+2 */
5399 p=MAXI(x->digits, set->digits)+h+2; /* [h<=8] */
5404 /* the accumulator needs to be able to hold 2p digits so that */
5415 /* the term needs to be able to hold p digits (which is */
5416 /* guaranteed to be larger than x->digits, so the initial copy */
5418 /* calculation below, which needs an extra two digits */
5437 aset.digits=p*2; /* double */
5439 tset.digits=p;
5441 /* [dset.digits=16, etc., are sufficient] */
5454 /* if rounded to p digits, which is when its value is smaller */
5455 /* than the accumulator by p+1 digits. There must also be */
5457 if (((a->digits+a->exponent)>=(t->digits+t->exponent+p+1))
5458 && (a->digits>=p)) break;
5466 (LI)iterations, (LI)*status, (LI)p, (LI)x->digits);
5476 aset.digits=p+2; /* sufficient precision */
5477 /* avoid the overhead and many extra digits of decNumberPower */
5501 aset.digits=set->digits; /* [use default rounding] */
5549 /* C must have space for set->digits digits. */
5559 /* digits, emax, and -emin in the context must be less than */
5656 if (rhs->exponent==0 && set->digits<=40) {
5658 if (rhs->lsu[0]==0 && rhs->lsu[1]==1 && rhs->digits==2) { /* ln(10) */
5660 if (rhs->lsu[0]==10 && rhs->digits==2) { /* ln(10) */
5667 if (rhs->lsu[0]==2 && rhs->digits==1) { /* ln(2) */
5677 /* the rhs is 'over-precise' then allow for all its digits to */
5679 /* digits are 9s) so in this case use rhs->digits+2. */
5680 p=MAXI(rhs->digits, MAXI(set->digits, 7))+2;
5684 /* be able to hold p digits, and the adjustment up to */
5685 /* rhs->digits+p digits. They are also made big enough for 16 */
5686 /* digits so that they can be used for calculating the initial */
5696 pp=p+rhs->digits;
5712 /* table (see above) indexed by the first two digits of f, */
5716 r=rhs->exponent+rhs->digits; /* 'normalised' exponent */
5721 /* now get top two digits of rhs into b by simple truncate and */
5724 aset.digits=2; aset.round=DEC_ROUND_DOWN;
5733 aset.digits=16; aset.round=DEC_ROUND_HALF_EVEN; /* restore */
5735 /* the initial estimate is now in a, with up to 4 digits correct. */
5751 /* for each iteration double the number of digits to calculate, */
5756 aset.digits=pp; /* working context */
5757 bset.digits=pp+rhs->digits; /* wider context */
5776 /* result by >=0.5 ulp (at the requested digits), which */
5778 /* set->digits+1 digits (or it is zero) -- this is a looser */
5784 (a->digits+a->exponent)>=(b->digits+b->exponent+set->digits+1)) {
5785 if (a->digits==p) break;
5802 aset.digits=pp; /* working context */
5803 bset.digits=pp+rhs->digits; /* wider context */
5810 (LI)iterations, (LI)*status, (LI)p, (LI)rhs->digits);
5816 aset.digits=set->digits; /* [use default rounding] */
5847 /* C must have space for set->digits digits. */
5860 Int reqdigits=set->digits; /* requested DIGITS */
5873 if (lhs->digits>reqdigits) {
5878 if (rhs->digits>reqdigits) { /* [this only checks lostDigits] */
5931 if ((lhs->digits-adjust)>reqdigits) {
5938 /* digits, and must round as it does so */
5941 workset.digits=lhs->digits-adjust; /* set requested length */
5950 /* set->digits==3 */
5951 if (res->digits==reqdigits) { /* cannot shift by 1 */
5956 res->digits=decShiftToMost(res->lsu, res->digits, 1); /* shift */
5965 /* digits, by adding zero or more trailing zeros; this is */
5970 res->digits=decShiftToMost(res->lsu, res->digits, -adjust);
5978 if (res->exponent>set->emax-res->digits+1) { /* too big */
6019 /* C must have space for one digit for COMPARE or set->digits for */
6043 if (lhs->digits>set->digits) {
6048 if (rhs->digits>set->digits) {
6086 result=decUnitCompare(lhs->lsu, D2U(lhs->digits),
6087 rhs->lsu, D2U(rhs->digits), 0);
6230 compare=decUnitCompare(lhs->lsu, D2U(lhs->digits),
6231 rhs->lsu, D2U(rhs->digits),
6405 /* here carry is new Unit of digits; it could be +ve or -ve */
6448 /* Can use QUOT10 as carry <= 4 digits */
6490 /* here carry is new Unit of digits; it could be +ve or -ve and */
6634 for (d=0; d<dn->digits-1; d++) { /* [don't strip the final digit] */
6660 Int maxd=set->emax-set->digits+1-dn->exponent;
6666 decShiftToLeast(dn->lsu, D2U(dn->digits), d);
6668 dn->digits-=d; /* new length */
6694 /* decShiftToMost -- shift digits in array towards most significant */
6697 /* digits is the count of digits in use in the array */
6701 /* returns the new length of the integer in the array, in digits */
6706 static Int decShiftToMost(Unit *uar, Int digits, Int shift) {
6711 if (shift==0) return digits; /* [fastpath] nothing to do */
6712 if ((digits+shift)<=DECDPUN) { /* [fastpath] single-unit case */
6714 return digits+shift;
6718 source=uar+D2U(digits)-1; /* where msu comes from */
6725 first=uar+D2U(digits+shift)-1; /* where msu of source will end up */
6746 return digits+shift;
6750 /* decShiftToLeast -- shift digits in array towards least significant */
6754 /* shift is the number of digits to remove from the lsu end; it */
6759 /* Removed digits are discarded (lost). Units not required to hold */
6769 *uar=0; /* all digits cleared gives zero */
6813 /* dn is the number to round (dn->digits is > set->digits) */
6837 +(D2U(set->digits)-1)*sizeof(Unit));
6845 /* If that set Inexact then "lost digits" is raised... */
6857 /* set is the context [used for length (digits) and rounding mode] */
6868 decSetCoeff(dest, set, src->lsu, src->digits, residue, status);
6875 /* It must have space for set->digits digits */
6878 /* len is digits in the source coefficient [may be dn->digits] */
6883 /* reflect the previous residue and the dropped digits. */
6888 /* dn->lsu and len must == dn->digits. */
6890 /* Note that the coefficient length (len) may be < set->digits, and */
6895 /* decSetSubnormal) the value of set->digits may be less than one, */
6899 /* dn->digits, dn->lsu (and as required), and dn->exponent are */
6902 /* DEC_Rounded status is set if any digits are discarded. */
6903 /* DEC_Inexact status is set if any non-zero digits are discarded, or */
6912 Int discard; /* number of digits to discard */
6921 discard=len-set->digits; /* digits to discard */
6922 if (discard<=0) { /* no digits are being discarded */
6929 dn->digits=len; /* set the new length */
6936 /* some digits must be discarded ... */
6953 dn->digits=1; /* .. */
6982 if (set->digits<=0) { /* special for Quantize/Subnormal :-( */
6984 dn->digits=1; /* .. */
6987 count=set->digits; /* now digits to end up with */
6988 dn->digits=count; /* set the new length */
7026 /* quot holds the uncut high-order digits for the current unit */
7027 if (set->digits<=0) { /* special for Quantize/Subnormal :-( */
7029 dn->digits=1; /* .. */
7032 count=set->digits; /* now digits to end up with */
7033 dn->digits=count; /* set the new length */
7062 /* dn is the number, with space for set->digits digits */
7070 /* -1: as 1, but the hidden digits are subtractive, that */
7179 uInt count=dn->digits; /* digits to be checked */
7189 if ((dn->exponent+dn->digits)>set->emax+1) {
7201 /* other digits zero) */
7203 uInt count=dn->digits; /* digits to be checked */
7219 /* dn->exponent, set->digits); */
7220 if (dn->exponent+1==set->emin-set->digits+1) {
7221 if (count==1 && dn->digits==1) *sup=0; /* here 9 -> 0[.9] */
7224 dn->digits--;
7240 decUnitAddSub(dn->lsu, D2U(dn->digits), uarrone, 1, 0, dn->lsu, bump);
7255 /* b. Reducing positive exponents to 0, if would fit in digits */
7270 if (set->digits >= (dn->exponent+dn->digits)) {
7271 dn->digits=decShiftToMost(dn->lsu, dn->digits, dn->exponent);
7298 Int tinyexp=set->emin-dn->digits+1; /* precalculate subnormal boundary */
7335 if (dn->exponent<=set->emax-set->digits+1) return; /* neither needed */
7339 if (dn->exponent>set->emax-dn->digits+1) { /* too big */
7347 shift=dn->exponent-(set->emax-set->digits+1);
7351 dn->digits=decShiftToMost(dn->lsu, dn->digits, shift);
7375 if (set->clamp) emax-=set->digits-1; /* lower if clamping */
7411 /* set is the context [used for digits and emax] */
7417 Int count=set->digits; /* nines to add */
7418 dn->digits=count;
7426 count-=DECDPUN; /* filled those digits */
7429 dn->exponent=set->emax-set->digits+1;
7466 etiny=set->emin-(set->digits-1); /* smallest allowed exponent */
7484 adjust=etiny-dn->exponent; /* calculate digits to remove */
7496 workset.digits=dn->digits-adjust; /* set requested length */
7499 decSetCoeff(dn, &workset, dn->lsu, dn->digits, residue, status);
7509 dn->digits=decShiftToMost(dn->lsu, dn->digits, 1);
7530 /* digits, emax, and -emin in the context must be less than */
7538 if (set->digits>DEC_MAX_MATH
7541 else if ((rhs->digits>DEC_MAX_MATH
7542 || rhs->exponent+rhs->digits>DEC_MAX_MATH+1
7543 || rhs->exponent+rhs->digits<2*(1-DEC_MAX_MATH))
7566 Int got; /* digits (real or not) processed */
7567 Int ilength=dn->digits+dn->exponent; /* integral length */
7570 /* The number must be an integer that fits in 10 digits */
7587 Int count=-dn->exponent; /* digits to discard */
7596 /* slice off fraction digits and check for non-zero */
7606 got=DECDPUN-count; /* number of digits so far */
7612 /* tricky code now, to accumulate up to 9.3 digits */
7644 /* drop is the number of digits to be removed from the left of dn; */
7645 /* this must be <= dn->digits (if equal, the coefficient is */
7648 /* Returns dn; dn->digits will be <= the initial digits less drop */
7649 /* (after removing drop digits there may be leading zero digits */
7650 /* which will also be removed). Only dn->lsu and dn->digits change. */
7655 if (drop>=dn->digits) { /* losing the whole thing */
7657 if (drop>dn->digits)
7658 printf("decDecap called with drop>digits [%ld>%ld]\n",
7659 (LI)drop, (LI)dn->digits);
7662 dn->digits=1;
7665 msu=dn->lsu+D2U(dn->digits-drop)-1; /* -> likely msu */
7666 cut=MSUDIGITS(dn->digits-drop); /* digits to be in use in msu */
7667 if (cut!=DECDPUN) *msu%=powers[cut]; /* clear left digits */
7668 /* that may have left leading zero digits, so do a proper count... */
7669 dn->digits=decGetDigits(dn->lsu, msu-dn->lsu+1);
7727 if (lhs->digits<=set->digits) uprv_decNumberCopy(res, lhs); /* easy */
7733 uresp1=res->lsu+D2U(set->digits);
7735 res->digits=D2U(set->digits)*DECDPUN;
7737 if (res->digits>set->digits) decDecap(res, res->digits-set->digits);
7776 /* decGetDigits -- count digits in a Units array */
7782 /* returns the number of (significant) digits in the array */
7790 Int digits=(len-1)*DECDPUN+1; /* possible digits excluding msu */
7801 if (digits==1) break; /* a zero has one digit */
7802 digits-=DECDPUN; /* adjust for 0 unit */
7807 digits++;
7810 digits++;
7813 digits++;
7815 for (pow=&powers[4]; *up>=*pow; pow++) digits++;
7822 return digits;
7830 /* Shows: sign, exponent, coefficient (msu first), digits */
7851 if (dn->exponent==0 && dn->digits==1 && *dn->lsu==0) {
7859 up=dn->lsu+D2U(dn->digits)-1; /* msu */
7875 printf(" [%ld]\n", (LI)dn->digits);
7941 && (set->digits<1 || set->round>=DEC_ROUND_MAX)) {
7944 printf("Bad context [digits=%ld round=%ld].\n",
7945 (LI)set->digits, (LI)set->round);
7980 Int ae, d, digits; /* .. */
8001 if (dn->digits!=1) {
8003 printf("Digits %ld (not 1) for an infinity.\n", (LI)dn->digits);
8010 decDumpAr('I', dn->lsu, D2U(dn->digits));
8019 if (dn->digits<1 || dn->digits>DECNUMMAXP) {
8021 printf("Digits %ld in number.\n", (LI)dn->digits);
8025 d=dn->digits;
8031 if (dn->digits>1 && *up<powers[d-1]) {
8041 (LI)*up, (LI)dn->digits, (LI)(up-dn->lsu), (LI)maxuint);
8048 /* which are out of the set->emin/set->emax and set->digits range */
8049 /* (just as they can have more digits than set->digits). */
8050 ae=dn->exponent+dn->digits-1; /* adjusted exponent */
8053 digits=DECNUMMAXP;
8054 if (ae<emin-(digits-1)) {
8071 /* decCheckInexact -- check a normal finite inexact result has digits */
8074 /* sets Invalid operation, etc., if some digits are missing */
8081 && (set->digits!=dn->digits) && !(dn->bits & DECSPECIAL)) {
8083 printf("Insufficient digits [%ld] on normal Inexact result.\n",
8084 (LI)dn->digits);
8091 if (dn!=NULL && dn->digits==0) set->status|=DEC_Invalid_operation;