• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.9.5/ICU-511.35/icuSources/i18n/

Lines Matching defs: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 */
216 /* round-for-reround digits */
334 /* complement of digits (where appropriate -- this is not the case */
385 dn->digits=decGetDigits(dn->lsu, up-dn->lsu);
404 /* special or too many digits, or bad exponent */
405 if (dn->bits&DECSPECIAL || dn->digits>10 || dn->exponent!=0) ; /* bad */
406 else { /* is a finite integer with 10 or fewer digits */
411 lo=*up; /* get 1 to 9 digits */
418 for (d=DECDPUN; d<dn->digits; up++, d+=DECDPUN) hi+=*up*powers[d-1];
439 /* special or too many digits, or bad exponent, or negative (<0) */
440 if (dn->bits&DECSPECIAL || dn->digits>10 || dn->exponent!=0
442 else { /* is a finite integer with 10 or fewer digits */
447 lo=*up; /* get 1 to 9 digits */
454 for (d=DECDPUN; d<dn->digits; up++, d+=DECDPUN) hi+=*up*powers[d-1];
474 /* string must be at least dn->digits+14 characters long */
496 /* (set.digits), determining the maximum and minimum */
516 Int d=0; /* count of digits found in decimal part */
537 d++; /* count of real digits */
557 if (last==NULL) { /* no digits yet */
598 if (*c!='\0') break; /* not all digits */
599 if (d>set->digits-1) {
601 /* clamped, in which case can only be digits-1] */
603 if (d>set->digits) break;
604 } /* too many digits? */
611 /* had some digits; exponent is only valid sequence now */
642 } /* stuff after digits */
668 /* OK, the digits string is good. Assemble in the decNumber, or in */
670 if (d<=set->digits) res=dn->lsu; /* fits into supplied decNumber */
687 cut=d-(up-res)*DECDPUN; /* digits in top unit */
688 for (c=cfirst;; c++) { /* along the digits */
713 dn->digits=d;
716 if (d>set->digits) {
724 if ((dn->exponent-1<set->emin-dn->digits)
725 || (dn->exponent-1>set->emax-set->digits)) {
752 /* C must have space for set->digits digits. */
786 /* C must have space for set->digits digits. */
810 /* C must have space for set->digits digits. */
820 Int msudigs; /* digits in res msu */
835 msua=ua+D2U(lhs->digits)-1; /* -> msu of lhs */
836 msub=ub+D2U(rhs->digits)-1; /* -> msu of rhs */
837 msuc=uc+D2U(set->digits)-1; /* -> msu of result */
838 msudigs=MSUDIGITS(set->digits); /* [faster than remainder] */
865 res->digits=decGetDigits(res->lsu, uc-res->lsu);
963 needbytes=sizeof(decNumber)+(D2U(lhs->digits)-1)*sizeof(Unit);
977 needbytes=sizeof(decNumber)+(D2U(rhs->digits)-1)*sizeof(Unit);
1008 /* C must have space for set->digits digits. */
1031 /* C must have space for set->digits digits. */
1050 /* C must have space for set->digits digits. */
1085 if (rhs->digits>set->digits) {
1120 /* C must have space for set->digits digits. */
1150 dcmul.digits=lhs->digits+rhs->digits; /* just enough */
1156 needbytes=sizeof(decNumber)+(D2U(dcmul.digits)-1)*sizeof(Unit);
1208 /* C must have space for set->digits digits. */
1217 Int msudigs; /* digits in res msu */
1229 msua=ua+D2U(rhs->digits)-1; /* -> msu of rhs */
1230 msuc=uc+D2U(set->digits)-1; /* -> msu of result */
1231 msudigs=MSUDIGITS(set->digits); /* [faster than remainder] */
1252 res->digits=decGetDigits(res->lsu, uc-res->lsu);
1267 /* C must have space for set->digits digits. */
1303 if (rhs->digits>set->digits) {
1335 /* set is the context, used only for digits and status */
1337 /* C must have space for 10 digits (A might have 10**9 digits and */
1342 /* with zeros on the right to set->digits digits while keeping the */
1369 Int ae=rhs->exponent+rhs->digits-1; /* adjusted exponent */
1386 /* C must have space for set->digits digits. */
1402 /* ln(A) this is the max(p, rhs->digits + t) + 3, where p is the */
1403 /* requested digits and t is the number of digits in the exponent */
1417 Int t; /* digits in exponent of A */
1445 if (rhs->digits>set->digits) {
1465 aset.digits=1;
1482 /* number of digits in a, including exponent' as compared to the */
1483 /* requested digits, as increasing this will only rarely cost an */
1488 p=(rhs->digits+t>set->digits?rhs->digits+t:set->digits)+3;
1497 aset.digits=p; /* as calculated */
1510 /* for ln(10) an extra 3 digits of precision are needed */
1511 p=set->digits+3;
1526 w->digits=2; /* .. */
1528 aset.digits=p;
1531 aset.digits=set->digits; /* for final divide */
1561 /* C must have space for set->digits digits. */
1584 /* C must have space for set->digits digits. */
1607 /* C must have space for set->digits digits. */
1630 /* C must have space for set->digits digits. */
1653 /* C must have space for set->digits digits. */
1826 /* C must have space for set->digits digits. */
1836 Int msudigs; /* digits in res msu */
1850 msua=ua+D2U(lhs->digits)-1; /* -> msu of lhs */
1851 msub=ub+D2U(rhs->digits)-1; /* -> msu of rhs */
1852 msuc=uc+D2U(set->digits)-1; /* -> msu of result */
1853 msudigs=MSUDIGITS(set->digits); /* [faster than remainder] */
1879 res->digits=decGetDigits(res->lsu, uc-res->lsu);
1895 /* C must have space for set->digits digits. */
1929 /* C must have space for set->digits digits. */
1952 /* C must have space for set->digits digits. */
1976 Int reqdigits=set->digits; /* requested DIGITS */
1992 /* local accumulator buffer [a decNumber, with digits+elength+1 digits] */
2005 if (lhs->digits>reqdigits) {
2010 if (rhs->digits>reqdigits) {
2039 Int shift=set->digits-1;
2041 res->digits=decShiftToMost(res->lsu, 1, shift);
2127 /* is the total digits, including exponent), or the requested */
2130 /* than the requested digits as it greatly reduces the >0.5 ulp */
2131 /* cases at little cost (because Ln doubles digits each */
2132 /* iteration so a few extra digits rarely causes an extra */
2134 aset.digits=MAXI(lhs->digits, set->digits)+6+4;
2149 aset.digits=reqdigits+(rhs->digits+rhs->exponent)+2;
2151 if (!set->extended) aset.digits--; /* use classic precision */
2154 if (aset.digits>DECNUMMAXP) {status|=DEC_Invalid_operation; break;}
2157 /* aset.digits is the count of digits for the accumulator needed */
2159 needbytes=sizeof(decNumber)+(D2U(aset.digits)-1)*sizeof(Unit);
2180 Int shift=set->digits-1;
2181 dac->digits=decShiftToMost(dac->lsu, 1, shift);
2199 if (decNumberIsNegative(rhs)) { /* was a **-n [hence digits>0] */
2258 /* round subnormals [to set.digits rather than aset.digits] */
2267 decNumberIsNegative(rhs)) { /* was a **-n [hence digits>0] */
2308 /* C must have space for set->digits digits. */
2330 /* C must have space for set->digits digits. */
2355 if (rhs->digits>set->digits) {
2397 /* C must have space for set->digits digits. */
2420 /* C must have space for set->digits digits. */
2443 /* C must have space for set->digits digits. */
2459 /* This computes C = A rot B (in base ten and rotating set->digits */
2460 /* digits). */
2464 /* rhs is B, the number of digits to rotate (-ve to right) */
2467 /* The digits of the coefficient of A are rotated to the left (if B */
2469 /* the exponent or the sign of A. If lhs->digits is less than */
2470 /* set->digits the coefficient is padded with zeros on the left */
2474 /* B must be an integer (q=0) and in the range -set->digits through */
2475 /* +set->digits. */
2476 /* C must have space for set->digits digits. */
2500 || abs(rotate)>set->digits) /* .. or out of range */
2505 if (rotate<0) rotate=set->digits+rotate;
2506 if (rotate!=0 && rotate!=set->digits /* zero or full rotation */
2508 /* left-rotate to do; 0 < rotate < set->digits */
2510 uInt msudigits; /* digits in result msu */
2511 Unit *msu=res->lsu+D2U(res->digits)-1; /* current msu */
2512 Unit *msumax=res->lsu+D2U(set->digits)-1; /* rotation msu */
2514 res->digits=set->digits; /* now full-length */
2515 msudigits=MSUDIGITS(res->digits); /* actual digits in msu */
2519 /* lsd [any digits shifted out are rotated to the left, */
2527 /* digits shifted out will fit exactly in the current msu, */
2533 /* example: rotate right 8 digits (2 units + 2), DECDPUN=3. */
2548 rotate=set->digits-rotate; /* make it right-rotate */
2550 shift=rotate%DECDPUN; /* left-over digits count */
2553 decShiftToLeast(res->lsu, D2U(res->digits), shift);
2554 if (shift>msudigits) { /* msumax-1 needs >0 digits */
2563 } /* digits shift needed */
2585 res->digits=decGetDigits(res->lsu, msumax-res->lsu+1);
2626 /* maximum magnitude 2*(emax+digits) */
2633 /* C must have space for set->digits digits. */
2658 || abs(reqexp)>(2*(set->digits+set->emax))) /* .. or out of range */
2680 /* rhs is B, the number of digits to shift (-ve to right) */
2683 /* The digits of the coefficient of A are shifted to the left (if B */
2687 /* B must be an integer (q=0) and in the range -set->digits through */
2688 /* +set->digits. */
2689 /* C must have space for set->digits digits. */
2713 || abs(shift)>set->digits) /* .. or out of range */
2719 if (shift==set->digits) { /* removing all */
2721 res->digits=1; /* .. */
2724 /* first remove leading digits if necessary */
2725 if (res->digits+shift>set->digits) {
2726 decDecap(res, res->digits+shift-set->digits);
2727 /* that updated res->digits; may have gone to 1 (for a */
2730 if (res->digits>1 || *res->lsu) /* if non-zero.. */
2731 res->digits=decShiftToMost(res->lsu, res->digits, shift);
2735 if (-shift>=res->digits) { /* discarding all */
2737 res->digits=1; /* .. */
2740 decShiftToLeast(res->lsu, D2U(res->digits), -shift);
2741 res->digits-=(-shift);
2760 /* C must have space for set->digits digits. */
2856 /* buffer for temporary variable, up to 3 digits */
2868 if (rhs->digits>set->digits) {
2916 workp=MAXI(set->digits+1, rhs->digits); /* actual rounding precision */
2920 needbytes=sizeof(decNumber)+(D2U(rhs->digits)-1)*sizeof(Unit);
2942 exp=f->exponent+f->digits; /* adjusted to Hull rules */
2943 f->exponent=-(f->digits); /* to range */
2954 workset.digits=workp; /* p for initial calculation */
2955 t->bits=0; t->digits=3;
2956 a->bits=0; a->digits=3;
3000 workset.digits=3; /* initial p */
3001 for (; workset.digits<maxp;) {
3003 workset.digits=MINI(workset.digits*2-2, maxp);
3011 /* Here, 0.1 <= a < 1 [Hull], and a has maxp digits */
3040 /* Here workset.digits=maxp and t=0.5, and a->digits determines */
3042 workset.digits--; /* maxp-1 is OK now */
3043 t->exponent=-a->digits-1; /* make 0.5 ulp */
3086 /* digits, so this is the only (relatively rare) condition that */
3088 if (b->digits*2-1 > workp) { /* cannot fit */
3107 Int maxexp=set->emax-set->digits+1;
3118 decShiftToLeast(a->lsu, D2U(a->digits), todrop);
3120 a->digits-=todrop; /* new length */
3130 Int ae=rhs->exponent+rhs->digits-1; /* adjusted exponent */
3170 /* C must have space for set->digits digits. */
3201 /* the digits setting is ignored. The Exact version will signal */
3225 workset.digits=rhs->digits; /* no length rounding */
3256 /* C must have space for set->digits digits. */
3266 Int msudigs; /* digits in res msu */
3280 msua=ua+D2U(lhs->digits)-1; /* -> msu of lhs */
3281 msub=ub+D2U(rhs->digits)-1; /* -> msu of rhs */
3282 msuc=uc+D2U(set->digits)-1; /* -> msu of result */
3283 msudigs=MSUDIGITS(set->digits); /* [faster than remainder] */
3309 res->digits=decGetDigits(res->lsu, uc-res->lsu);
3393 dest->digits=src->digits;
3395 if (src->digits>DECDPUN) { /* more Units to come */
3401 smsup=src->lsu+D2U(src->digits); /* -> source msu+1 */
3415 /* C must have space for set->digits digits. */
3436 /* C must have space for set->digits digits. */
3458 /* C must have space for set->digits digits. */
3477 /* bcd is the uInt array that will receive dn->digits BCD bytes, */
3481 /* bcd must have at least dn->digits bytes. No error is possible; if */
3482 /* dn is a NaN or Infinite, digits must be 1 and the coefficient 0. */
3485 uByte *ub=bcd+dn->digits-1; /* -> lsd */
3511 /* n is the number of digits in the source BCD array (bcd) */
3514 /* dn must have space for at least n digits. No error is possible; */
3519 Unit *up=dn->lsu+D2U(dn->digits)-1; /* -> msu [target pointer] */
3525 /* calculate how many digits in msu, and hence first cut */
3528 *up=0; /* will take <=DECDPUN digits */
3530 cut=DECDPUN; /* next Unit has all digits */
3533 dn->digits=n; /* set digit count */
3552 ae=dn->exponent+dn->digits-1; /* adjusted exponent */
3572 ae=dn->exponent+dn->digits-1; /* adjusted exponent */
3623 dn->digits=1;
3639 /* string must be at least dn->digits+14 characters long */
3651 Int pre; /* digits before the '.' */
3652 Int cut; /* for counting digits in a Unit */
3654 const Unit *up=dn->lsu+D2U(dn->digits)-1; /* -> msu [input pointer] */
3681 if (exp!=0 || (*dn->lsu==0 && dn->digits==1)) return;
3685 /* calculate how many digits in msu, and hence first cut */
3686 cut=MSUDIGITS(dn->digits); /* [faster than remainder] */
3691 u=*up; /* contains DECDPUN digits to lay out */
3693 cut=DECDPUN-1; /* next Unit has all digits */
3699 pre=dn->digits+exp; /* digits before '.' */
3702 e=exp+dn->digits-1; /* calculate E value */
3729 /* lay out the digits of the coefficient, adding 0s and . as needed */
3735 if (up==dn->lsu) break; /* out of input digits (pre>digits) */
3742 if (n<dn->digits) { /* more to come, after '.' */
3746 if (up==dn->lsu) break; /* out of input digits */
3762 if (up==dn->lsu) break; /* out of input digits */
3807 /* C must have space for set->digits digits. */
3812 /* -- a digits+1 calculation is needed because the numbers are */
3813 /* unaligned and span more than set->digits digits */
3814 /* -- a carry to digits+1 digits looks possible */
3848 Int reqdigits=set->digits; /* local copy; requested DIGITS */
3859 if (lhs->digits>reqdigits) {
3864 if (rhs->digits>reqdigits) {
3920 if ((res->digits-adjust)>set->digits) {
3921 adjust=res->digits-set->digits; /* to fit exactly */
3924 res->digits=decShiftToMost(res->lsu, res->digits, -adjust);
3947 if ((res->digits-adjust)>set->digits) {
3948 adjust=res->digits-set->digits; /* to fit exactly */
3951 res->digits=decShiftToMost(res->lsu, res->digits, -adjust);
3970 && rhs->digits<=DECDPUN
3972 && rhs->exponent<=set->emax-set->digits+1 /* [could clamp] */
3973 && rhs->digits<=reqdigits
3974 && lhs->digits<=reqdigits) {
3979 && (lhs->digits>=DECDPUN || /* .. and no digits-count change */
3980 partial<(Int)powers[lhs->digits])) { /* .. */
3992 /* this could have reduced digits [but result>0] */
3993 res->digits=decGetDigits(res->lsu, D2U(res->digits));
4025 /* If, after pad, rhs would be longer than lhs by digits+1 or */
4028 if (rhs->digits+padding > lhs->digits+reqdigits+1) {
4031 Int shift=reqdigits-rhs->digits; /* left shift needed */
4038 res->digits=decShiftToMost(res->lsu, res->digits, shift);
4046 /* LHS digits may affect result */
4054 maxdigits=rhs->digits+padding; /* virtual length of RHS */
4055 if (lhs->digits>maxdigits) maxdigits=lhs->digits;
4065 /* buffer needed, choose it; units for maxdigits digits will be */
4083 decDumpAr('A', lhs->lsu, D2U(lhs->digits));
4084 decDumpAr('B', rhs->lsu, D2U(rhs->digits));
4089 U_ASSERT(rhs->digits > 0);
4090 U_ASSERT(lhs->digits > 0);
4091 res->digits=decUnitAddSub(lhs->lsu, D2U(lhs->digits),
4092 rhs->lsu, D2U(rhs->digits),
4094 *DECDPUN; /* [units -> digits] */
4095 if (res->digits<0) { /* borrowed... */
4096 res->digits=-res->digits;
4100 decDumpAr('+', acc, D2U(res->digits));
4113 if (res->digits>reqdigits)
4114 res->digits=decGetDigits(acc, D2U(res->digits));
4115 decSetCoeff(res, set, acc, res->digits, &residue, status);
4120 /* numbers fit in DECDPUN digits and are padding with a */
4124 if (res->digits<maxdigits) {
4125 *(acc+D2U(res->digits))=0; /* ensure leading 0 is there */
4126 res->digits=maxdigits;
4132 if (res->digits>reqdigits) {
4133 res->digits=decGetDigits(acc, D2U(res->digits));
4134 if (res->digits<maxdigits) res->digits=maxdigits;
4137 decSetCoeff(res, set, acc, res->digits, &residue, status);
4149 res->digits=decGetDigits(res->lsu, D2U(res->digits));
4191 /* C must have space for set->digits digits. */
4210 /* Do until (have=digits+1 OR residue=0) */
4239 /* Two working buffers are needed during the division; one (digits+ */
4240 /* 1) to accumulate the result, and the other (up to 2*digits+1) for */
4259 Int accdigits; /* count of digits accumulated */
4273 Int var1initpad=0; /* var1 initial padding (digits) */
4278 Int reqdigits=set->digits; /* requested DIGITS */
4298 if (lhs->digits>reqdigits) {
4303 if (rhs->digits>reqdigits) {
4344 res->exponent=set->emin-set->digits+1;
4401 exponent=(lhs->exponent+lhs->digits)-(rhs->exponent+rhs->digits);
4447 /* (rhs->digits+reqdigits-1) -- to allow full slide to right */
4448 /* or (lhs->digits) -- to allow for long lhs */
4454 maxdigits=rhs->digits+reqdigits-1;
4455 if (lhs->digits>maxdigits) maxdigits=lhs->digits;
4475 source=lhs->lsu+D2U(lhs->digits)-1; /* msu of input array */
4481 var2units=D2U(rhs->digits); /* rhs actual length (units) */
4499 /* [This is actually done by counting the digits and negating, as */
4511 /* save the initial 'false' padding of var1, in digits */
4512 var1initpad=(var1units-D2U(lhs->digits))*DECDPUN;
4534 accdigits=0; /* .. or digits */
4535 accnext=acc+acclength-1; /* -> msu of acc [NB: allows digits+1] */
4603 /* account exactly for the new digits */
4611 if (accdigits>reqdigits) break; /* have enough digits */
4615 /* or divideInteger and still not enough digits yet) */
4635 /* accunits is the number of digits collected in acc */
4714 /* calculate the unused zero digits. This is the smaller of: */
4721 /* shift var1 the requested amount, and adjust its digits */
4746 compare=decUnitCompare(accnext, tarunits, rhs->lsu, D2U(rhs->digits),
4779 quotdigits-=DECDPUN; /* checked those digits */
4794 rhs->lsu, D2U(rhs->digits),
4796 accdigits=decGetDigits(accnext, accunits); /* count digits exactly */
4840 /* C must have space for set->digits digits. */
4887 #define FASTDIGS 9 /* digits in base */
4952 if (lhs->digits<rhs->digits) { /* swap... */
4962 if (lhs->digits>set->digits) {
4967 if (rhs->digits>set->digits) {
4977 /* use the fast path if there are enough digits in the shorter */
4980 if (rhs->digits>NEEDTWO) { /* use fastpath... */
4982 ilhs=(lhs->digits+FASTDIGS-1)/FASTDIGS; /* [ceiling] */
4983 irhs=(rhs->digits+FASTDIGS-1)/FASTDIGS; /* .. */
5005 /* if the given numbers have less digits than DEC_MAX_DIGITS. */
5025 for (count=lhs->digits, cup=lhs->lsu, lip=zlhi; count>0; lip++)
5030 for (count=rhs->digits, cup=rhs->lsu, rip=zrhi; count>0; rip++)
5047 /* add -- every 162 digits. Similarly, when FASTDIGS=8, the */
5050 /* resolution occurs only every 14752 digits. Hence for common */
5107 needbytes=(D2U(lhs->digits)+D2U(rhs->digits))*sizeof(Unit);
5122 madlength=D2U(lhs->digits); /* this won't change */
5123 mermsup=rhs->lsu+D2U(rhs->digits); /* -> msu+1 of multiplier */
5151 res->digits=decGetDigits(acc, accunits); /* count digits exactly */
5165 decSetCoeff(res, set, acc, res->digits, &residue, status);
5190 /* C must have space for set->digits digits. status is updated but */
5195 /* digits, emax, and -emin in the context must be less than */
5277 /* the working precision will be no more than set->digits+8+1 */
5289 /* decNumber for the divisor term; this needs at most 9 digits */
5323 /* set->digits-1 zeros between the decimal point and the digit, */
5326 /* 1.0000001. Hence, tiny will be 0.0000004 if digits=7 and x>0 */
5327 /* or 0.00000004 if digits=7 and x<0. If RHS not larger than */
5331 d->exponent=-set->digits; /* * 10**(-d) */
5338 Int shift=set->digits-1;
5341 res->digits=decShiftToMost(res->lsu, 1, shift);
5356 h=rhs->exponent+rhs->digits;
5373 Int maxlever=(rhs->digits>8?1:0);
5379 /* Apply as much as possible, up to a MAXLEVER digits, which */
5382 /* increases to compensate for the "constant digits at the */
5385 Int use=-rhs->digits-lever; /* exponent to use for RHS */
5394 needbytes=sizeof(decNumber)+(D2U(rhs->digits)-1)*sizeof(Unit);
5414 /* this is set->digits+h+2. However, if x is 'over-precise' we */
5415 /* need to allow for all its digits to potentially participate */
5416 /* (consider an x where all the excess digits are 9s) so in */
5417 /* this case use x->digits+h+2 */
5418 p=MAXI(x->digits, set->digits)+h+2; /* [h<=8] */
5423 /* the accumulator needs to be able to hold 2p digits so that */
5434 /* the term needs to be able to hold p digits (which is */
5435 /* guaranteed to be larger than x->digits, so the initial copy */
5437 /* calculation below, which needs an extra two digits */
5456 aset.digits=p*2; /* double */
5458 tset.digits=p;
5460 /* [dset.digits=16, etc., are sufficient] */
5473 /* if rounded to p digits, which is when its value is smaller */
5474 /* than the accumulator by p+1 digits. There must also be */
5476 if (((a->digits+a->exponent)>=(t->digits+t->exponent+p+1))
5477 && (a->digits>=p)) break;
5485 (LI)iterations, (LI)*status, (LI)p, (LI)x->digits);
5495 aset.digits=p+2; /* sufficient precision */
5496 /* avoid the overhead and many extra digits of decNumberPower */
5520 aset.digits=set->digits; /* [use default rounding] */
5568 /* C must have space for set->digits digits. */
5578 /* digits, emax, and -emin in the context must be less than */
5675 if (rhs->exponent==0 && set->digits<=40) {
5677 if (rhs->lsu[0]==0 && rhs->lsu[1]==1 && rhs->digits==2) { /* ln(10) */
5679 if (rhs->lsu[0]==10 && rhs->digits==2) { /* ln(10) */
5686 if (rhs->lsu[0]==2 && rhs->digits==1) { /* ln(2) */
5696 /* the rhs is 'over-precise' then allow for all its digits to */
5698 /* digits are 9s) so in this case use rhs->digits+2. */
5699 p=MAXI(rhs->digits, MAXI(set->digits, 7))+2;
5703 /* be able to hold p digits, and the adjustment up to */
5704 /* rhs->digits+p digits. They are also made big enough for 16 */
5705 /* digits so that they can be used for calculating the initial */
5715 pp=p+rhs->digits;
5731 /* table (see above) indexed by the first two digits of f, */
5735 r=rhs->exponent+rhs->digits; /* 'normalised' exponent */
5740 /* now get top two digits of rhs into b by simple truncate and */
5743 aset.digits=2; aset.round=DEC_ROUND_DOWN;
5752 aset.digits=16; aset.round=DEC_ROUND_HALF_EVEN; /* restore */
5754 /* the initial estimate is now in a, with up to 4 digits correct. */
5770 /* for each iteration double the number of digits to calculate, */
5775 aset.digits=pp; /* working context */
5776 bset.digits=pp+rhs->digits; /* wider context */
5795 /* result by >=0.5 ulp (at the requested digits), which */
5797 /* set->digits+1 digits (or it is zero) -- this is a looser */
5803 (a->digits+a->exponent)>=(b->digits+b->exponent+set->digits+1)) {
5804 if (a->digits==p) break;
5821 aset.digits=pp; /* working context */
5822 bset.digits=pp+rhs->digits; /* wider context */
5829 (LI)iterations, (LI)*status, (LI)p, (LI)rhs->digits);
5835 aset.digits=set->digits; /* [use default rounding] */
5866 /* C must have space for set->digits digits. */
5879 Int reqdigits=set->digits; /* requested DIGITS */
5892 if (lhs->digits>reqdigits) {
5897 if (rhs->digits>reqdigits) { /* [this only checks lostDigits] */
5950 if ((lhs->digits-adjust)>reqdigits) {
5957 /* digits, and must round as it does so */
5960 workset.digits=lhs->digits-adjust; /* set requested length */
5969 /* set->digits==3 */
5970 if (res->digits==reqdigits) { /* cannot shift by 1 */
5975 res->digits=decShiftToMost(res->lsu, res->digits, 1); /* shift */
5984 /* digits, by adding zero or more trailing zeros; this is */
5989 res->digits=decShiftToMost(res->lsu, res->digits, -adjust);
5997 if (res->exponent>set->emax-res->digits+1) { /* too big */
6038 /* C must have space for one digit for COMPARE or set->digits for */
6062 if (lhs->digits>set->digits) {
6067 if (rhs->digits>set->digits) {
6105 result=decUnitCompare(lhs->lsu, D2U(lhs->digits),
6106 rhs->lsu, D2U(rhs->digits), 0);
6249 compare=decUnitCompare(lhs->lsu, D2U(lhs->digits),
6250 rhs->lsu, D2U(rhs->digits),
6424 /* here carry is new Unit of digits; it could be +ve or -ve */
6467 /* Can use QUOT10 as carry <= 4 digits */
6509 /* here carry is new Unit of digits; it could be +ve or -ve and */
6653 for (d=0; d<dn->digits-1; d++) { /* [don't strip the final digit] */
6679 Int maxd=set->emax-set->digits+1-dn->exponent;
6685 decShiftToLeast(dn->lsu, D2U(dn->digits), d);
6687 dn->digits-=d; /* new length */
6713 /* decShiftToMost -- shift digits in array towards most significant */
6716 /* digits is the count of digits in use in the array */
6720 /* returns the new length of the integer in the array, in digits */
6725 static Int decShiftToMost(Unit *uar, Int digits, Int shift) {
6730 if (shift==0) return digits; /* [fastpath] nothing to do */
6731 if ((digits+shift)<=DECDPUN) { /* [fastpath] single-unit case */
6733 return digits+shift;
6737 source=uar+D2U(digits)-1; /* where msu comes from */
6744 first=uar+D2U(digits+shift)-1; /* where msu of source will end up */
6765 return digits+shift;
6769 /* decShiftToLeast -- shift digits in array towards least significant */
6773 /* shift is the number of digits to remove from the lsu end; it */
6778 /* Removed digits are discarded (lost). Units not required to hold */
6788 *uar=0; /* all digits cleared gives zero */
6832 /* dn is the number to round (dn->digits is > set->digits) */
6856 +(D2U(set->digits)-1)*sizeof(Unit));
6864 /* If that set Inexact then "lost digits" is raised... */
6876 /* set is the context [used for length (digits) and rounding mode] */
6887 decSetCoeff(dest, set, src->lsu, src->digits, residue, status);
6894 /* It must have space for set->digits digits */
6897 /* len is digits in the source coefficient [may be dn->digits] */
6902 /* reflect the previous residue and the dropped digits. */
6907 /* dn->lsu and len must == dn->digits. */
6909 /* Note that the coefficient length (len) may be < set->digits, and */
6914 /* decSetSubnormal) the value of set->digits may be less than one, */
6918 /* dn->digits, dn->lsu (and as required), and dn->exponent are */
6921 /* DEC_Rounded status is set if any digits are discarded. */
6922 /* DEC_Inexact status is set if any non-zero digits are discarded, or */
6931 Int discard; /* number of digits to discard */
6940 discard=len-set->digits; /* digits to discard */
6941 if (discard<=0) { /* no digits are being discarded */
6948 dn->digits=len; /* set the new length */
6955 /* some digits must be discarded ... */
6972 dn->digits=1; /* .. */
7001 if (set->digits<=0) { /* special for Quantize/Subnormal :-( */
7003 dn->digits=1; /* .. */
7006 count=set->digits; /* now digits to end up with */
7007 dn->digits=count; /* set the new length */
7046 /* quot holds the uncut high-order digits for the current unit */
7047 if (set->digits<=0) { /* special for Quantize/Subnormal :-( */
7049 dn->digits=1; /* .. */
7052 count=set->digits; /* now digits to end up with */
7053 dn->digits=count; /* set the new length */
7082 /* dn is the number, with space for set->digits digits */
7090 /* -1: as 1, but the hidden digits are subtractive, that */
7199 uInt count=dn->digits; /* digits to be checked */
7209 if ((dn->exponent+dn->digits)>set->emax+1) {
7221 /* other digits zero) */
7223 uInt count=dn->digits; /* digits to be checked */
7239 /* dn->exponent, set->digits); */
7240 if (dn->exponent+1==set->emin-set->digits+1) {
7241 if (count==1 && dn->digits==1) *sup=0; /* here 9 -> 0[.9] */
7244 dn->digits--;
7260 decUnitAddSub(dn->lsu, D2U(dn->digits), uarrone, 1, 0, dn->lsu, bump);
7275 /* b. Reducing positive exponents to 0, if would fit in digits */
7290 if (set->digits >= (dn->exponent+dn->digits)) {
7291 dn->digits=decShiftToMost(dn->lsu, dn->digits, dn->exponent);
7318 Int tinyexp=set->emin-dn->digits+1; /* precalculate subnormal boundary */
7355 if (dn->exponent<=set->emax-set->digits+1) return; /* neither needed */
7359 if (dn->exponent>set->emax-dn->digits+1) { /* too big */
7367 shift=dn->exponent-(set->emax-set->digits+1);
7371 dn->digits=decShiftToMost(dn->lsu, dn->digits, shift);
7395 if (set->clamp) emax-=set->digits-1; /* lower if clamping */
7431 /* set is the context [used for digits and emax] */
7437 Int count=set->digits; /* nines to add */
7438 dn->digits=count;
7446 count-=DECDPUN; /* filled those digits */
7449 dn->exponent=set->emax-set->digits+1;
7486 etiny=set->emin-(set->digits-1); /* smallest allowed exponent */
7504 adjust=etiny-dn->exponent; /* calculate digits to remove */
7516 workset.digits=dn->digits-adjust; /* set requested length */
7519 decSetCoeff(dn, &workset, dn->lsu, dn->digits, residue, status);
7529 dn->digits=decShiftToMost(dn->lsu, dn->digits, 1);
7550 /* digits, emax, and -emin in the context must be less than */
7558 if (set->digits>DEC_MAX_MATH
7561 else if ((rhs->digits>DEC_MAX_MATH
7562 || rhs->exponent+rhs->digits>DEC_MAX_MATH+1
7563 || rhs->exponent+rhs->digits<2*(1-DEC_MAX_MATH))
7586 Int got; /* digits (real or not) processed */
7587 Int ilength=dn->digits+dn->exponent; /* integral length */
7590 /* The number must be an integer that fits in 10 digits */
7607 Int count=-dn->exponent; /* digits to discard */
7616 /* slice off fraction digits and check for non-zero */
7626 got=DECDPUN-count; /* number of digits so far */
7632 /* tricky code now, to accumulate up to 9.3 digits */
7664 /* drop is the number of digits to be removed from the left of dn; */
7665 /* this must be <= dn->digits (if equal, the coefficient is */
7668 /* Returns dn; dn->digits will be <= the initial digits less drop */
7669 /* (after removing drop digits there may be leading zero digits */
7670 /* which will also be removed). Only dn->lsu and dn->digits change. */
7675 if (drop>=dn->digits) { /* losing the whole thing */
7677 if (drop>dn->digits)
7678 printf("decDecap called with drop>digits [%ld>%ld]\n",
7679 (LI)drop, (LI)dn->digits);
7682 dn->digits=1;
7685 msu=dn->lsu+D2U(dn->digits-drop)-1; /* -> likely msu */
7686 cut=MSUDIGITS(dn->digits-drop); /* digits to be in use in msu */
7687 if (cut!=DECDPUN) *msu%=powers[cut]; /* clear left digits */
7688 /* that may have left leading zero digits, so do a proper count... */
7689 dn->digits=decGetDigits(dn->lsu, msu-dn->lsu+1);
7747 if (lhs->digits<=set->digits) uprv_decNumberCopy(res, lhs); /* easy */
7753 uresp1=res->lsu+D2U(set->digits);
7755 res->digits=D2U(set->digits)*DECDPUN;
7757 if (res->digits>set->digits) decDecap(res, res->digits-set->digits);
7796 /* decGetDigits -- count digits in a Units array */
7802 /* returns the number of (significant) digits in the array */
7810 Int digits=(len-1)*DECDPUN+1; /* possible digits excluding msu */
7821 if (digits==1) break; /* a zero has one digit */
7822 digits-=DECDPUN; /* adjust for 0 unit */
7827 digits++;
7830 digits++;
7833 digits++;
7835 for (pow=&powers[4]; *up>=*pow; pow++) digits++;
7842 return digits;
7850 /* Shows: sign, exponent, coefficient (msu first), digits */
7871 if (dn->exponent==0 && dn->digits==1 && *dn->lsu==0) {
7879 up=dn->lsu+D2U(dn->digits)-1; /* msu */
7895 printf(" [%ld]\n", (LI)dn->digits);
7961 && (set->digits<1 || set->round>=DEC_ROUND_MAX)) {
7964 printf("Bad context [digits=%ld round=%ld].\n",
7965 (LI)set->digits, (LI)set->round);
8000 Int ae, d, digits; /* .. */
8021 if (dn->digits!=1) {
8023 printf("Digits %ld (not 1) for an infinity.\n", (LI)dn->digits);
8030 decDumpAr('I', dn->lsu, D2U(dn->digits));
8039 if (dn->digits<1 || dn->digits>DECNUMMAXP) {
8041 printf("Digits %ld in number.\n", (LI)dn->digits);
8045 d=dn->digits;
8051 if (dn->digits>1 && *up<powers[d-1]) {
8061 (LI)*up, (LI)dn->digits, (LI)(up-dn->lsu), (LI)maxuint);
8068 /* which are out of the set->emin/set->emax and set->digits range */
8069 /* (just as they can have more digits than set->digits). */
8070 ae=dn->exponent+dn->digits-1; /* adjusted exponent */
8073 digits=DECNUMMAXP;
8074 if (ae<emin-(digits-1)) {
8091 /* decCheckInexact -- check a normal finite inexact result has digits */
8094 /* sets Invalid operation, etc., if some digits are missing */
8101 && (set->digits!=dn->digits) && !(dn->bits & DECSPECIAL)) {
8103 printf("Insufficient digits [%ld] on normal Inexact result.\n",
8104 (LI)dn->digits);
8111 if (dn!=NULL && dn->digits==0) set->status|=DEC_Invalid_operation;