Home | History | Annotate | Download | only in i18n

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 */
1402 Int t; /* digits in exponent of A */
1430 if (rhs->digits>set->digits) {
1450 aset.digits=1;
1467 /* number of digits in a, including exponent' as compared to the */
1468 /* requested digits, as increasing this will only rarely cost an */
1473 p=(rhs->digits+t>set->digits?rhs->digits+t:set->digits)+3;
1482 aset.digits=p; /* as calculated */
1495 /* for ln(10) an extra 3 digits of precision are needed */
1496 p=set->digits+3;
1511 w->digits=2; /* .. */
1513 aset.digits=p;
1516 aset.digits=set->digits; /* for final divide */
1544 /* C must have space for set->digits digits. */
1567 /* C must have space for set->digits digits. */
1590 /* C must have space for set->digits digits. */
1613 /* C must have space for set->digits digits. */
1636 /* C must have space for set->digits digits. */
1809 /* C must have space for set->digits digits. */
1819 Int msudigs; /* digits in res msu */
1833 msua=ua+D2U(lhs->digits)-1; /* -> msu of lhs */
1834 msub=ub+D2U(rhs->digits)-1; /* -> msu of rhs */
1835 msuc=uc+D2U(set->digits)-1; /* -> msu of result */
1836 msudigs=MSUDIGITS(set->digits); /* [faster than remainder] */
1862 res->digits=decGetDigits(res->lsu, uc-res->lsu);
1878 /* C must have space for set->digits digits. */
1912 /* C must have space for set->digits digits. */
1935 /* C must have space for set->digits digits. */
1959 Int reqdigits=set->digits; /* requested DIGITS */
1975 /* local accumulator buffer [a decNumber, with digits+elength+1 digits] */
1988 if (lhs->digits>reqdigits) {
1993 if (rhs->digits>reqdigits) {
2022 Int shift=set->digits-1;
2024 res->digits=decShiftToMost(res->lsu, 1, shift);
2110 /* is the total digits, including exponent), or the requested */
2113 /* than the requested digits as it greatly reduces the >0.5 ulp */
2114 /* cases at little cost (because Ln doubles digits each */
2115 /* iteration so a few extra digits rarely causes an extra */
2117 aset.digits=MAXI(lhs->digits, set->digits)+6+4;
2131 /* calculate the working DIGITS */
2132 aset.digits=reqdigits+(rhs->digits+rhs->exponent)+2;
2134 if (!set->extended) aset.digits--; /* use classic precision */
2137 if (aset.digits>DECNUMMAXP) {status|=DEC_Invalid_operation; break;}
2140 /* aset.digits is the count of digits for the accumulator needed */
2142 needbytes=sizeof(decNumber)+(D2U(aset.digits)-1)*sizeof(Unit);
2163 Int shift=set->digits-1;
2164 dac->digits=decShiftToMost(dac->lsu, 1, shift);
2182 if (decNumberIsNegative(rhs)) { /* was a **-n [hence digits>0] */
2241 /* round subnormals [to set.digits rather than aset.digits] */
2250 decNumberIsNegative(rhs)) { /* was a **-n [hence digits>0] */
2291 /* C must have space for set->digits digits. */
2313 /* C must have space for set->digits digits. */
2338 if (rhs->digits>set->digits) {
2380 /* C must have space for set->digits digits. */
2403 /* C must have space for set->digits digits. */
2426 /* C must have space for set->digits digits. */
2442 /* This computes C = A rot B (in base ten and rotating set->digits */
2443 /* digits). */
2447 /* rhs is B, the number of digits to rotate (-ve to right) */
2450 /* The digits of the coefficient of A are rotated to the left (if B */
2452 /* the exponent or the sign of A. If lhs->digits is less than */
2453 /* set->digits the coefficient is padded with zeros on the left */
2457 /* B must be an integer (q=0) and in the range -set->digits through */
2458 /* +set->digits. */
2459 /* C must have space for set->digits digits. */
2483 || abs(rotate)>set->digits) /* .. or out of range */
2488 if (rotate<0) rotate=set->digits+rotate;
2489 if (rotate!=0 && rotate!=set->digits /* zero or full rotation */
2491 /* left-rotate to do; 0 < rotate < set->digits */
2493 uInt msudigits; /* digits in result msu */
2494 Unit *msu=res->lsu+D2U(res->digits)-1; /* current msu */
2495 Unit *msumax=res->lsu+D2U(set->digits)-1; /* rotation msu */
2497 res->digits=set->digits; /* now full-length */
2498 msudigits=MSUDIGITS(res->digits); /* actual digits in msu */
2502 /* lsd [any digits shifted out are rotated to the left, */
2510 /* digits shifted out will fit exactly in the current msu, */
2516 /* example: rotate right 8 digits (2 units + 2), DECDPUN=3. */
2531 rotate=set->digits-rotate; /* make it right-rotate */
2533 shift=rotate%DECDPUN; /* left-over digits count */
2536 decShiftToLeast(res->lsu, D2U(res->digits), shift);
2537 if (shift>msudigits) { /* msumax-1 needs >0 digits */
2546 } /* digits shift needed */
2568 res->digits=decGetDigits(res->lsu, msumax-res->lsu+1);
2609 /* maximum magnitude 2*(emax+digits) */
2616 /* C must have space for set->digits digits. */
2641 || abs(reqexp)>(2*(set->digits+set->emax))) /* .. or out of range */
2663 /* rhs is B, the number of digits to shift (-ve to right) */
2666 /* The digits of the coefficient of A are shifted to the left (if B */
2670 /* B must be an integer (q=0) and in the range -set->digits through */
2671 /* +set->digits. */
2672 /* C must have space for set->digits digits. */
2696 || abs(shift)>set->digits) /* .. or out of range */
2702 if (shift==set->digits) { /* removing all */
2704 res->digits=1; /* .. */
2707 /* first remove leading digits if necessary */
2708 if (res->digits+shift>set->digits) {
2709 decDecap(res, res->digits+shift-set->digits);
2710 /* that updated res->digits; may have gone to 1 (for a */
2713 if (res->digits>1 || *res->lsu) /* if non-zero.. */
2714 res->digits=decShiftToMost(res->lsu, res->digits, shift);
2718 if (-shift>=res->digits) { /* discarding all */
2720 res->digits=1; /* .. */
2723 decShiftToLeast(res->lsu, D2U(res->digits), -shift);
2724 res->digits-=(-shift);
2743 /* C must have space for set->digits digits. */
2837 /* buffer for temporary variable, up to 3 digits */
2849 if (rhs->digits>set->digits) {
2897 workp=MAXI(set->digits+1, rhs->digits); /* actual rounding precision */
2901 needbytes=sizeof(decNumber)+(D2U(rhs->digits)-1)*sizeof(Unit);
2923 exp=f->exponent+f->digits; /* adjusted to Hull rules */
2924 f->exponent=-(f->digits); /* to range */
2935 workset.digits=workp; /* p for initial calculation */
2936 t->bits=0; t->digits=3;
2937 a->bits=0; a->digits=3;
2981 workset.digits=3; /* initial p */
2982 for (; workset.digits<maxp;) {
2984 workset.digits=MINI(workset.digits*2-2, maxp);
2992 /* Here, 0.1 <= a < 1 [Hull], and a has maxp digits */
3021 /* Here workset.digits=maxp and t=0.5, and a->digits determines */
3023 workset.digits--; /* maxp-1 is OK now */
3024 t->exponent=-a->digits-1; /* make 0.5 ulp */
3067 /* digits, so this is the only (relatively rare) condition that */
3069 if (b->digits*2-1 > workp) { /* cannot fit */
3088 Int maxexp=set->emax-set->digits+1;
3099 decShiftToLeast(a->lsu, D2U(a->digits), todrop);
3101 a->digits-=todrop; /* new length */
3111 Int ae=rhs->exponent+rhs->digits-1; /* adjusted exponent */
3149 /* C must have space for set->digits digits. */
3180 /* the digits setting is ignored. The Exact version will signal */
3204 workset.digits=rhs->digits; /* no length rounding */
3235 /* C must have space for set->digits digits. */
3245 Int msudigs; /* digits in res msu */
3259 msua=ua+D2U(lhs->digits)-1; /* -> msu of lhs */
3260 msub=ub+D2U(rhs->digits)-1; /* -> msu of rhs */
3261 msuc=uc+D2U(set->digits)-1; /* -> msu of result */
3262 msudigs=MSUDIGITS(set->digits); /* [faster than remainder] */
3288 res->digits=decGetDigits(res->lsu, uc-res->lsu);
3372 dest->digits=src->digits;
3374 if (src->digits>DECDPUN) { /* more Units to come */
3380 smsup=src->lsu+D2U(src->digits); /* -> source msu+1 */
3394 /* C must have space for set->digits digits. */
3415 /* C must have space for set->digits digits. */
3437 /* C must have space for set->digits digits. */
3456 /* bcd is the uInt array that will receive dn->digits BCD bytes, */
3460 /* bcd must have at least dn->digits bytes. No error is possible; if */
3461 /* dn is a NaN or Infinite, digits must be 1 and the coefficient 0. */
3464 uByte *ub=bcd+dn->digits-1; /* -> lsd */
3490 /* n is the number of digits in the source BCD array (bcd) */
3493 /* dn must have space for at least n digits. No error is possible; */
3498 Unit *up=dn->lsu+D2U(dn->digits)-1; /* -> msu [target pointer] */
3504 /* calculate how many digits in msu, and hence first cut */
3507 *up=0; /* will take <=DECDPUN digits */
3509 cut=DECDPUN; /* next Unit has all digits */
3512 dn->digits=n; /* set digit count */
3531 ae=dn->exponent+dn->digits-1; /* adjusted exponent */
3551 ae=dn->exponent+dn->digits-1; /* adjusted exponent */
3602 dn->digits=1;
3618 /* string must be at least dn->digits+14 characters long */
3630 Int pre; /* digits before the '.' */
3631 Int cut; /* for counting digits in a Unit */
3633 const Unit *up=dn->lsu+D2U(dn->digits)-1; /* -> msu [input pointer] */
3660 if (exp!=0 || (*dn->lsu==0 && dn->digits==1)) return;
3664 /* calculate how many digits in msu, and hence first cut */
3665 cut=MSUDIGITS(dn->digits); /* [faster than remainder] */
3670 u=*up; /* contains DECDPUN digits to lay out */
3672 cut=DECDPUN-1; /* next Unit has all digits */
3678 pre=dn->digits+exp; /* digits before '.' */
3681 e=exp+dn->digits-1; /* calculate E value */
3708 /* lay out the digits of the coefficient, adding 0s and . as needed */
3714 if (up==dn->lsu) break; /* out of input digits (pre>digits) */
3721 if (n<dn->digits) { /* more to come, after '.' */
3725 if (up==dn->lsu) break; /* out of input digits */
3741 if (up==dn->lsu) break; /* out of input digits */
3786 /* C must have space for set->digits digits. */
3791 /* -- a digits+1 calculation is needed because the numbers are */
3792 /* unaligned and span more than set->digits digits */
3793 /* -- a carry to digits+1 digits looks possible */
3827 Int reqdigits=set->digits; /* local copy; requested DIGITS */
3838 if (lhs->digits>reqdigits) {
3843 if (rhs->digits>reqdigits) {
3899 if ((res->digits-adjust)>set->digits) {
3900 adjust=res->digits-set->digits; /* to fit exactly */
3903 res->digits=decShiftToMost(res->lsu, res->digits, -adjust);
3926 if ((res->digits-adjust)>set->digits) {
3927 adjust=res->digits-set->digits; /* to fit exactly */
3930 res->digits=decShiftToMost(res->lsu, res->digits, -adjust);
3949 && rhs->digits<=DECDPUN
3951 && rhs->exponent<=set->emax-set->digits+1 /* [could clamp] */
3952 && rhs->digits<=reqdigits
3953 && lhs->digits<=reqdigits) {
3958 && (lhs->digits>=DECDPUN || /* .. and no digits-count change */
3959 partial<(Int)powers[lhs->digits])) { /* .. */
3971 /* this could have reduced digits [but result>0] */
3972 res->digits=decGetDigits(res->lsu, D2U(res->digits));
3983 /* other) padding with up to DIGITS-1 trailing zeros may be */
4004 /* If, after pad, rhs would be longer than lhs by digits+1 or */
4006 /* so only need to pad up to a length of DIGITS+1. */
4007 if (rhs->digits+padding > lhs->digits+reqdigits+1) {
4010 Int shift=reqdigits-rhs->digits; /* left shift needed */
4017 res->digits=decShiftToMost(res->lsu, res->digits, shift);
4025 /* LHS digits may affect result */
4033 maxdigits=rhs->digits+padding; /* virtual length of RHS */
4034 if (lhs->digits>maxdigits) maxdigits=lhs->digits;
4040 /* borrow to DIGITS+1 might be possible, a buffer must be used. */
4044 /* buffer needed, choose it; units for maxdigits digits will be */
4062 decDumpAr('A', lhs->lsu, D2U(lhs->digits));
4063 decDumpAr('B', rhs->lsu, D2U(rhs->digits));
4068 res->digits=decUnitAddSub(lhs->lsu, D2U(lhs->digits),
4069 rhs->lsu, D2U(rhs->digits),
4071 *DECDPUN; /* [units -> digits] */
4072 if (res->digits<0) { /* borrowed... */
4073 res->digits=-res->digits;
4077 decDumpAr('+', acc, D2U(res->digits));
4090 if (res->digits>reqdigits)
4091 res->digits=decGetDigits(acc, D2U(res->digits));
4092 decSetCoeff(res, set, acc, res->digits, &residue, status);
4097 /* numbers fit in DECDPUN digits and are padding with a */
4101 if (res->digits<maxdigits) {
4102 *(acc+D2U(res->digits))=0; /* ensure leading 0 is there */
4103 res->digits=maxdigits;
4109 if (res->digits>reqdigits) {
4110 res->digits=decGetDigits(acc, D2U(res->digits));
4111 if (res->digits<maxdigits) res->digits=maxdigits;
4114 decSetCoeff(res, set, acc, res->digits, &residue, status);
4126 res->digits=decGetDigits(res->lsu, D2U(res->digits));
4168 /* C must have space for set->digits digits. */
4187 /* Do until (have=digits+1 OR residue=0) */
4216 /* Two working buffers are needed during the division; one (digits+ */
4217 /* 1) to accumulate the result, and the other (up to 2*digits+1) for */
4236 Int accdigits; /* count of digits accumulated */
4250 Int var1initpad=0; /* var1 initial padding (digits) */
4255 Int reqdigits=set->digits; /* requested DIGITS */
4275 if (lhs->digits>reqdigits) {
4280 if (rhs->digits>reqdigits) {
4321 res->exponent=set->emin-set->digits+1;
4378 exponent=(lhs->exponent+lhs->digits)-(rhs->exponent+rhs->digits);
4424 /* (rhs->digits+reqdigits-1) -- to allow full slide to right */
4425 /* or (lhs->digits) -- to allow for long lhs */
4431 maxdigits=rhs->digits+reqdigits-1;
4432 if (lhs->digits>maxdigits) maxdigits=lhs->digits;
4452 source=lhs->lsu+D2U(lhs->digits)-1; /* msu of input array */
4458 var2units=D2U(rhs->digits); /* rhs actual length (units) */
4476 /* [This is actually done by counting the digits and negating, as */
4488 /* save the initial 'false' padding of var1, in digits */
4489 var1initpad=(var1units-D2U(lhs->digits))*DECDPUN;
4511 accdigits=0; /* .. or digits */
4512 accnext=acc+acclength-1; /* -> msu of acc [NB: allows digits+1] */
4580 /* account exactly for the new digits */
4588 if (accdigits>reqdigits) break; /* have enough digits */
4592 /* or divideInteger and still not enough digits yet) */
4612 /* accunits is the number of digits collected in acc */
4691 /* calculate the unused zero digits. This is the smaller of: */
4698 /* shift var1 the requested amount, and adjust its digits */
4723 compare=decUnitCompare(accnext, tarunits, rhs->lsu, D2U(rhs->digits),
4756 quotdigits-=DECDPUN; /* checked those digits */
4771 rhs->lsu, D2U(rhs->digits),
4773 accdigits=decGetDigits(accnext, accunits); /* count digits exactly */
4817 /* C must have space for set->digits digits. */
4864 #define FASTDIGS 9 /* digits in base */
4929 if (lhs->digits<rhs->digits) { /* swap... */
4939 if (lhs->digits>set->digits) {
4944 if (rhs->digits>set->digits) {
4954 /* use the fast path if there are enough digits in the shorter */
4957 if (rhs->digits>NEEDTWO) { /* use fastpath... */
4959 ilhs=(lhs->digits+FASTDIGS-1)/FASTDIGS; /* [ceiling] */
4960 irhs=(rhs->digits+FASTDIGS-1)/FASTDIGS; /* .. */
4998 for (count=lhs->digits, cup=lhs->lsu, lip=zlhi; count>0; lip++)
5003 for (count=rhs->digits, cup=rhs->lsu, rip=zrhi; count>0; rip++)
5020 /* add -- every 162 digits. Similarly, when FASTDIGS=8, the */
5023 /* resolution occurs only every 14752 digits. Hence for common */
5080 needbytes=(D2U(lhs->digits)+D2U(rhs->digits))*sizeof(Unit);
5095 madlength=D2U(lhs->digits); /* this won't change */
5096 mermsup=rhs->lsu+D2U(rhs->digits); /* -> msu+1 of multiplier */
5124 res->digits=decGetDigits(acc, accunits); /* count digits exactly */
5138 decSetCoeff(res, set, acc, res->digits, &residue, status);
5163 /* C must have space for set->digits digits. status is updated but */
5168 /* digits, emax, and -emin in the context must be less than */
5250 /* the working precision will be no more than set->digits+8+1 */
5262 /* decNumber for the divisor term; this needs at most 9 digits */
5296 /* set->digits-1 zeros between the decimal point and the digit, */
5299 /* 1.0000001. Hence, tiny will be 0.0000004 if digits=7 and x>0 */
5300 /* or 0.00000004 if digits=7 and x<0. If RHS not larger than */
5304 d->exponent=-set->digits; /* * 10**(-d) */
5311 Int shift=set->digits-1;
5314 res->digits=decShiftToMost(res->lsu, 1, shift);
5329 h=rhs->exponent+rhs->digits;
5346 Int maxlever=(rhs->digits>8?1:0);
5352 /* Apply as much as possible, up to a MAXLEVER digits, which */
5355 /* increases to compensate for the "constant digits at the */
5358 Int use=-rhs->digits-lever; /* exponent to use for RHS */
5367 needbytes=sizeof(decNumber)+(D2U(rhs->digits)-1)*sizeof(Unit);
5387 /* this is set->digits+h+2. However, if x is 'over-precise' we */
5388 /* need to allow for all its digits to potentially participate */
5389 /* (consider an x where all the excess digits are 9s) so in */
5390 /* this case use x->digits+h+2 */
5391 p=MAXI(x->digits, set->digits)+h+2; /* [h<=8] */
5396 /* the accumulator needs to be able to hold 2p digits so that */
5407 /* the term needs to be able to hold p digits (which is */
5408 /* guaranteed to be larger than x->digits, so the initial copy */
5410 /* calculation below, which needs an extra two digits */
5429 aset.digits=p*2; /* double */
5431 tset.digits=p;
5433 /* [dset.digits=16, etc., are sufficient] */
5446 /* if rounded to p digits, which is when its value is smaller */
5447 /* than the accumulator by p+1 digits. There must also be */
5449 if (((a->digits+a->exponent)>=(t->digits+t->exponent+p+1))
5450 && (a->digits>=p)) break;
5458 (LI)iterations, (LI)*status, (LI)p, (LI)x->digits);
5468 aset.digits=p+2; /* sufficient precision */
5469 /* avoid the overhead and many extra digits of decNumberPower */
5493 aset.digits=set->digits; /* [use default rounding] */
5541 /* C must have space for set->digits digits. */
5551 /* digits, emax, and -emin in the context must be less than */
5646 if (rhs->exponent==0 && set->digits<=40) {
5648 if (rhs->lsu[0]==0 && rhs->lsu[1]==1 && rhs->digits==2) { /* ln(10) */
5650 if (rhs->lsu[0]==10 && rhs->digits==2) { /* ln(10) */
5657 if (rhs->lsu[0]==2 && rhs->digits==1) { /* ln(2) */
5667 /* the rhs is 'over-precise' then allow for all its digits to */
5669 /* digits are 9s) so in this case use rhs->digits+2. */
5670 p=MAXI(rhs->digits, MAXI(set->digits, 7))+2;
5674 /* be able to hold p digits, and the adjustment up to */
5675 /* rhs->digits+p digits. They are also made big enough for 16 */
5676 /* digits so that they can be used for calculating the initial */
5686 pp=p+rhs->digits;
5702 /* table (see above) indexed by the first two digits of f, */
5706 r=rhs->exponent+rhs->digits; /* 'normalised' exponent */
5711 /* now get top two digits of rhs into b by simple truncate and */
5714 aset.digits=2; aset.round=DEC_ROUND_DOWN;
5723 aset.digits=16; aset.round=DEC_ROUND_HALF_EVEN; /* restore */
5725 /* the initial estimate is now in a, with up to 4 digits correct. */
5741 /* for each iteration double the number of digits to calculate, */
5746 aset.digits=pp; /* working context */
5747 bset.digits=pp+rhs->digits; /* wider context */
5766 /* result by >=0.5 ulp (at the requested digits), which */
5768 /* set->digits+1 digits (or it is zero) -- this is a looser */
5774 (a->digits+a->exponent)>=(b->digits+b->exponent+set->digits+1)) {
5775 if (a->digits==p) break;
5792 aset.digits=pp; /* working context */
5793 bset.digits=pp+rhs->digits; /* wider context */
5800 (LI)iterations, (LI)*status, (LI)p, (LI)rhs->digits);
5806 aset.digits=set->digits; /* [use default rounding] */
5835 /* C must have space for set->digits digits. */
5848 Int reqdigits=set->digits; /* requested DIGITS */
5861 if (lhs->digits>reqdigits) {
5866 if (rhs->digits>reqdigits) { /* [this only checks lostDigits] */
5919 if ((lhs->digits-adjust)>reqdigits) {
5926 /* digits, and must round as it does so */
5929 workset.digits=lhs->digits-adjust; /* set requested length */
5938 /* set->digits==3 */
5939 if (res->digits==reqdigits) { /* cannot shift by 1 */
5944 res->digits=decShiftToMost(res->lsu, res->digits, 1); /* shift */
5953 /* digits, by adding zero or more trailing zeros; this is */
5958 res->digits=decShiftToMost(res->lsu, res->digits, -adjust);
5966 if (res->exponent>set->emax-res->digits+1) { /* too big */
6007 /* C must have space for one digit for COMPARE or set->digits for */
6031 if (lhs->digits>set->digits) {
6036 if (rhs->digits>set->digits) {
6074 result=decUnitCompare(lhs->lsu, D2U(lhs->digits),
6075 rhs->lsu, D2U(rhs->digits), 0);
6218 compare=decUnitCompare(lhs->lsu, D2U(lhs->digits),
6219 rhs->lsu, D2U(rhs->digits),
6393 /* here carry is new Unit of digits; it could be +ve or -ve */
6436 /* Can use QUOT10 as carry <= 4 digits */
6478 /* here carry is new Unit of digits; it could be +ve or -ve and */
6622 for (d=0; d<dn->digits-1; d++) { /* [don't strip the final digit] */
6648 Int maxd=set->emax-set->digits+1-dn->exponent;
6654 decShiftToLeast(dn->lsu, D2U(dn->digits), d);
6656 dn->digits-=d; /* new length */
6682 /* decShiftToMost -- shift digits in array towards most significant */
6685 /* digits is the count of digits in use in the array */
6689 /* returns the new length of the integer in the array, in digits */
6694 static Int decShiftToMost(Unit *uar, Int digits, Int shift) {
6699 if (shift==0) return digits; /* [fastpath] nothing to do */
6700 if ((digits+shift)<=DECDPUN) { /* [fastpath] single-unit case */
6702 return digits+shift;
6706 source=uar+D2U(digits)-1; /* where msu comes from */
6713 first=uar+D2U(digits+shift)-1; /* where msu of source will end up */
6734 return digits+shift;
6738 /* decShiftToLeast -- shift digits in array towards least significant */
6742 /* shift is the number of digits to remove from the lsu end; it */
6747 /* Removed digits are discarded (lost). Units not required to hold */
6757 *uar=0; /* all digits cleared gives zero */
6801 /* dn is the number to round (dn->digits is > set->digits) */
6825 +(D2U(set->digits)-1)*sizeof(Unit));
6833 /* If that set Inexact then "lost digits" is raised... */
6845 /* set is the context [used for length (digits) and rounding mode] */
6856 decSetCoeff(dest, set, src->lsu, src->digits, residue, status);
6863 /* It must have space for set->digits digits */
6866 /* len is digits in the source coefficient [may be dn->digits] */
6871 /* reflect the previous residue and the dropped digits. */
6876 /* dn->lsu and len must == dn->digits. */
6878 /* Note that the coefficient length (len) may be < set->digits, and */
6883 /* decSetSubnormal) the value of set->digits may be less than one, */
6887 /* dn->digits, dn->lsu (and as required), and dn->exponent are */
6890 /* DEC_Rounded status is set if any digits are discarded. */
6891 /* DEC_Inexact status is set if any non-zero digits are discarded, or */
6900 Int discard; /* number of digits to discard */
6909 discard=len-set->digits; /* digits to discard */
6910 if (discard<=0) { /* no digits are being discarded */
6917 dn->digits=len; /* set the new length */
6924 /* some digits must be discarded ... */
6941 dn->digits=1; /* .. */
6970 if (set->digits<=0) { /* special for Quantize/Subnormal :-( */
6972 dn->digits=1; /* .. */
6975 count=set->digits; /* now digits to end up with */
6976 dn->digits=count; /* set the new length */
7014 /* quot holds the uncut high-order digits for the current unit */
7015 if (set->digits<=0) { /* special for Quantize/Subnormal :-( */
7017 dn->digits=1; /* .. */
7020 count=set->digits; /* now digits to end up with */
7021 dn->digits=count; /* set the new length */
7050 /* dn is the number, with space for set->digits digits */
7058 /* -1: as 1, but the hidden digits are subtractive, that */
7167 uInt count=dn->digits; /* digits to be checked */
7177 if ((dn->exponent+dn->digits)>set->emax+1) {
7189 /* other digits zero) */
7191 uInt count=dn->digits; /* digits to be checked */
7207 /* dn->exponent, set->digits); */
7208 if (dn->exponent+1==set->emin-set->digits+1) {
7209 if (count==1 && dn->digits==1) *sup=0; /* here 9 -> 0[.9] */
7212 dn->digits--;
7228 decUnitAddSub(dn->lsu, D2U(dn->digits), uarrone, 1, 0, dn->lsu, bump);
7243 /* b. Reducing positive exponents to 0, if would fit in digits */
7258 if (set->digits >= (dn->exponent+dn->digits)) {
7259 dn->digits=decShiftToMost(dn->lsu, dn->digits, dn->exponent);
7286 Int tinyexp=set->emin-dn->digits+1; /* precalculate subnormal boundary */
7323 if (dn->exponent<=set->emax-set->digits+1) return; /* neither needed */
7327 if (dn->exponent>set->emax-dn->digits+1) { /* too big */
7335 shift=dn->exponent-(set->emax-set->digits+1);
7339 dn->digits=decShiftToMost(dn->lsu, dn->digits, shift);
7363 if (set->clamp) emax-=set->digits-1; /* lower if clamping */
7399 /* set is the context [used for digits and emax] */
7405 Int count=set->digits; /* nines to add */
7406 dn->digits=count;
7414 count-=DECDPUN; /* filled those digits */
7417 dn->exponent=set->emax-set->digits+1;
7454 etiny=set->emin-(set->digits-1); /* smallest allowed exponent */
7472 adjust=etiny-dn->exponent; /* calculate digits to remove */
7484 workset.digits=dn->digits-adjust; /* set requested length */
7487 decSetCoeff(dn, &workset, dn->lsu, dn->digits, residue, status);
7497 dn->digits=decShiftToMost(dn->lsu, dn->digits, 1);
7518 /* digits, emax, and -emin in the context must be less than */
7526 if (set->digits>DEC_MAX_MATH
7529 else if ((rhs->digits>DEC_MAX_MATH
7530 || rhs->exponent+rhs->digits>DEC_MAX_MATH+1
7531 || rhs->exponent+rhs->digits<2*(1-DEC_MAX_MATH))
7554 Int got; /* digits (real or not) processed */
7555 Int ilength=dn->digits+dn->exponent; /* integral length */
7558 /* The number must be an integer that fits in 10 digits */
7575 Int count=-dn->exponent; /* digits to discard */
7584 /* slice off fraction digits and check for non-zero */
7594 got=DECDPUN-count; /* number of digits so far */
7600 /* tricky code now, to accumulate up to 9.3 digits */
7632 /* drop is the number of digits to be removed from the left of dn; */
7633 /* this must be <= dn->digits (if equal, the coefficient is */
7636 /* Returns dn; dn->digits will be <= the initial digits less drop */
7637 /* (after removing drop digits there may be leading zero digits */
7638 /* which will also be removed). Only dn->lsu and dn->digits change. */
7643 if (drop>=dn->digits) { /* losing the whole thing */
7645 if (drop>dn->digits)
7646 printf("decDecap called with drop>digits [%ld>%ld]\n",
7647 (LI)drop, (LI)dn->digits);
7650 dn->digits=1;
7653 msu=dn->lsu+D2U(dn->digits-drop)-1; /* -> likely msu */
7654 cut=MSUDIGITS(dn->digits-drop); /* digits to be in use in msu */
7655 if (cut!=DECDPUN) *msu%=powers[cut]; /* clear left digits */
7656 /* that may have left leading zero digits, so do a proper count... */
7657 dn->digits=decGetDigits(dn->lsu, msu-dn->lsu+1);
7715 if (lhs->digits<=set->digits) uprv_decNumberCopy(res, lhs); /* easy */
7721 uresp1=res->lsu+D2U(set->digits);
7723 res->digits=D2U(set->digits)*DECDPUN;
7725 if (res->digits>set->digits) decDecap(res, res->digits-set->digits);
7764 /* decGetDigits -- count digits in a Units array */
7770 /* returns the number of (significant) digits in the array */
7778 Int digits=(len-1)*DECDPUN+1; /* possible digits excluding msu */
7789 if (digits==1) break; /* a zero has one digit */
7790 digits-=DECDPUN; /* adjust for 0 unit */
7795 digits++;
7798 digits++;
7801 digits++;
7803 for (pow=&powers[4]; *up>=*pow; pow++) digits++;
7810 return digits;
7818 /* Shows: sign, exponent, coefficient (msu first), digits */
7839 if (dn->exponent==0 && dn->digits==1 && *dn->lsu==0) {
7847 up=dn->lsu+D2U(dn->digits)-1; /* msu */
7863 printf(" [%ld]\n", (LI)dn->digits);
7929 && (set->digits<1 || set->round>=DEC_ROUND_MAX)) {
7932 printf("Bad context [digits=%ld round=%ld].\n",
7933 (LI)set->digits, (LI)set->round);
7968 Int ae, d, digits; /* .. */
7989 if (dn->digits!=1) {
7991 printf("Digits %ld (not 1) for an infinity.\n", (LI)dn->digits);
7998 decDumpAr('I', dn->lsu, D2U(dn->digits));
8007 if (dn->digits<1 || dn->digits>DECNUMMAXP) {
8009 printf("Digits %ld in number.\n", (LI)dn->digits);
8013 d=dn->digits;
8019 if (dn->digits>1 && *up<powers[d-1]) {
8029 (LI)*up, (LI)dn->digits, (LI)(up-dn->lsu), (LI)maxuint);
8036 /* which are out of the set->emin/set->emax and set->digits range */
8037 /* (just as they can have more digits than set->digits). */
8038 ae=dn->exponent+dn->digits-1; /* adjusted exponent */
8041 digits=DECNUMMAXP;
8042 if (ae<emin-(digits-1)) {
8059 /* decCheckInexact -- check a normal finite inexact result has digits */
8062 /* sets Invalid operation, etc., if some digits are missing */
8069 && (set->digits!=dn->digits) && !(dn->bits & DECSPECIAL)) {
8071 printf("Insufficient digits [%ld] on normal Inexact result.\n",
8072 (LI)dn->digits);
8079 if (dn!=NULL && dn->digits==0) set->status|=DEC_Invalid_operation;