• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.10.1/ICU-531.30/icuSources/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 */
216 /* round-for-reround digits */
336 /* complement of digits (where appropriate -- this is not the case */
387 dn->digits=decGetDigits(dn->lsu, up-dn->lsu);
406 /* special or too many digits, or bad exponent */
407 if (dn->bits&DECSPECIAL || dn->digits>10 || dn->exponent!=0) ; /* bad */
408 else { /* is a finite integer with 10 or fewer digits */
413 lo=*up; /* get 1 to 9 digits */
420 for (d=DECDPUN; d<dn->digits; up++, d+=DECDPUN) hi+=*up*powers[d-1];
441 /* special or too many digits, or bad exponent, or negative (<0) */
442 if (dn->bits&DECSPECIAL || dn->digits>10 || dn->exponent!=0
444 else { /* is a finite integer with 10 or fewer digits */
449 lo=*up; /* get 1 to 9 digits */
456 for (d=DECDPUN; d<dn->digits; up++, d+=DECDPUN) hi+=*up*powers[d-1];
476 /* string must be at least dn->digits+14 characters long */
498 /* (set.digits), determining the maximum and minimum */
518 Int d=0; /* count of digits found in decimal part */
539 d++; /* count of real digits */
559 if (last==NULL) { /* no digits yet */
600 if (*c!='\0') break; /* not all digits */
601 if (d>set->digits-1) {
603 /* clamped, in which case can only be digits-1] */
605 if (d>set->digits) break;
606 } /* too many digits? */
613 /* had some digits; exponent is only valid sequence now */
644 } /* stuff after digits */
670 /* OK, the digits string is good. Assemble in the decNumber, or in */
672 if (d<=set->digits) res=dn->lsu; /* fits into supplied decNumber */
689 cut=d-(up-res)*DECDPUN; /* digits in top unit */
690 for (c=cfirst;; c++) { /* along the digits */
715 dn->digits=d;
718 if (d>set->digits) {
726 if ((dn->exponent-1<set->emin-dn->digits)
727 || (dn->exponent-1>set->emax-set->digits)) {
754 /* C must have space for set->digits digits. */
788 /* C must have space for set->digits digits. */
812 /* C must have space for set->digits digits. */
822 Int msudigs; /* digits in res msu */
837 msua=ua+D2U(lhs->digits)-1; /* -> msu of lhs */
838 msub=ub+D2U(rhs->digits)-1; /* -> msu of rhs */
839 msuc=uc+D2U(set->digits)-1; /* -> msu of result */
840 msudigs=MSUDIGITS(set->digits); /* [faster than remainder] */
867 res->digits=decGetDigits(res->lsu, uc-res->lsu);
965 needbytes=sizeof(decNumber)+(D2U(lhs->digits)-1)*sizeof(Unit);
979 needbytes=sizeof(decNumber)+(D2U(rhs->digits)-1)*sizeof(Unit);
1010 /* C must have space for set->digits digits. */
1033 /* C must have space for set->digits digits. */
1052 /* C must have space for set->digits digits. */
1087 if (rhs->digits>set->digits) {
1122 /* C must have space for set->digits digits. */
1152 dcmul.digits=lhs->digits+rhs->digits; /* just enough */
1158 needbytes=sizeof(decNumber)+(D2U(dcmul.digits)-1)*sizeof(Unit);
1210 /* C must have space for set->digits digits. */
1219 Int msudigs; /* digits in res msu */
1231 msua=ua+D2U(rhs->digits)-1; /* -> msu of rhs */
1232 msuc=uc+D2U(set->digits)-1; /* -> msu of result */
1233 msudigs=MSUDIGITS(set->digits); /* [faster than remainder] */
1254 res->digits=decGetDigits(res->lsu, uc-res->lsu);
1269 /* C must have space for set->digits digits. */
1305 if (rhs->digits>set->digits) {
1337 /* set is the context, used only for digits and status */
1339 /* C must have space for 10 digits (A might have 10**9 digits and */
1344 /* with zeros on the right to set->digits digits while keeping the */
1371 Int ae=rhs->exponent+rhs->digits-1; /* adjusted exponent */
1388 /* C must have space for set->digits digits. */
1404 /* ln(A) this is the max(p, rhs->digits + t) + 3, where p is the */
1405 /* requested digits and t is the number of digits in the exponent */
1419 Int t; /* digits in exponent of A */
1447 if (rhs->digits>set->digits) {
1467 aset.digits=1;
1484 /* number of digits in a, including exponent' as compared to the */
1485 /* requested digits, as increasing this will only rarely cost an */
1490 p=(rhs->digits+t>set->digits?rhs->digits+t:set->digits)+3;
1499 aset.digits=p; /* as calculated */
1512 /* for ln(10) an extra 3 digits of precision are needed */
1513 p=set->digits+3;
1528 w->digits=2; /* .. */
1530 aset.digits=p;
1533 aset.digits=set->digits; /* for final divide */
1563 /* C must have space for set->digits digits. */
1586 /* C must have space for set->digits digits. */
1609 /* C must have space for set->digits digits. */
1632 /* C must have space for set->digits digits. */
1655 /* C must have space for set->digits digits. */
1828 /* C must have space for set->digits digits. */
1838 Int msudigs; /* digits in res msu */
1852 msua=ua+D2U(lhs->digits)-1; /* -> msu of lhs */
1853 msub=ub+D2U(rhs->digits)-1; /* -> msu of rhs */
1854 msuc=uc+D2U(set->digits)-1; /* -> msu of result */
1855 msudigs=MSUDIGITS(set->digits); /* [faster than remainder] */
1881 res->digits=decGetDigits(res->lsu, uc-res->lsu);
1897 /* C must have space for set->digits digits. */
1931 /* C must have space for set->digits digits. */
1954 /* C must have space for set->digits digits. */
1978 Int reqdigits=set->digits; /* requested DIGITS */
1994 /* local accumulator buffer [a decNumber, with digits+elength+1 digits] */
2007 if (lhs->digits>reqdigits) {
2012 if (rhs->digits>reqdigits) {
2041 Int shift=set->digits-1;
2043 res->digits=decShiftToMost(res->lsu, 1, shift);
2129 /* is the total digits, including exponent), or the requested */
2132 /* than the requested digits as it greatly reduces the >0.5 ulp */
2133 /* cases at little cost (because Ln doubles digits each */
2134 /* iteration so a few extra digits rarely causes an extra */
2136 aset.digits=MAXI(lhs->digits, set->digits)+6+4;
2151 aset.digits=reqdigits+(rhs->digits+rhs->exponent)+2;
2153 if (!set->extended) aset.digits--; /* use classic precision */
2156 if (aset.digits>DECNUMMAXP) {status|=DEC_Invalid_operation; break;}
2159 /* aset.digits is the count of digits for the accumulator needed */
2161 needbytes=sizeof(decNumber)+(D2U(aset.digits)-1)*sizeof(Unit);
2182 Int shift=set->digits-1;
2183 dac->digits=decShiftToMost(dac->lsu, 1, shift);
2201 if (decNumberIsNegative(rhs)) { /* was a **-n [hence digits>0] */
2260 /* round subnormals [to set.digits rather than aset.digits] */
2269 decNumberIsNegative(rhs)) { /* was a **-n [hence digits>0] */
2310 /* C must have space for set->digits digits. */
2332 /* C must have space for set->digits digits. */
2357 if (rhs->digits>set->digits) {
2399 /* C must have space for set->digits digits. */
2422 /* C must have space for set->digits digits. */
2445 /* C must have space for set->digits digits. */
2461 /* This computes C = A rot B (in base ten and rotating set->digits */
2462 /* digits). */
2466 /* rhs is B, the number of digits to rotate (-ve to right) */
2469 /* The digits of the coefficient of A are rotated to the left (if B */
2471 /* the exponent or the sign of A. If lhs->digits is less than */
2472 /* set->digits the coefficient is padded with zeros on the left */
2476 /* B must be an integer (q=0) and in the range -set->digits through */
2477 /* +set->digits. */
2478 /* C must have space for set->digits digits. */
2502 || abs(rotate)>set->digits) /* .. or out of range */
2507 if (rotate<0) rotate=set->digits+rotate;
2508 if (rotate!=0 && rotate!=set->digits /* zero or full rotation */
2510 /* left-rotate to do; 0 < rotate < set->digits */
2512 uInt msudigits; /* digits in result msu */
2513 Unit *msu=res->lsu+D2U(res->digits)-1; /* current msu */
2514 Unit *msumax=res->lsu+D2U(set->digits)-1; /* rotation msu */
2516 res->digits=set->digits; /* now full-length */
2517 msudigits=MSUDIGITS(res->digits); /* actual digits in msu */
2521 /* lsd [any digits shifted out are rotated to the left, */
2529 /* digits shifted out will fit exactly in the current msu, */
2535 /* example: rotate right 8 digits (2 units + 2), DECDPUN=3. */
2550 rotate=set->digits-rotate; /* make it right-rotate */
2552 shift=rotate%DECDPUN; /* left-over digits count */
2555 decShiftToLeast(res->lsu, D2U(res->digits), shift);
2556 if (shift>msudigits) { /* msumax-1 needs >0 digits */
2565 } /* digits shift needed */
2587 res->digits=decGetDigits(res->lsu, msumax-res->lsu+1);
2628 /* maximum magnitude 2*(emax+digits) */
2635 /* C must have space for set->digits digits. */
2660 || abs(reqexp)>(2*(set->digits+set->emax))) /* .. or out of range */
2682 /* rhs is B, the number of digits to shift (-ve to right) */
2685 /* The digits of the coefficient of A are shifted to the left (if B */
2689 /* B must be an integer (q=0) and in the range -set->digits through */
2690 /* +set->digits. */
2691 /* C must have space for set->digits digits. */
2715 || abs(shift)>set->digits) /* .. or out of range */
2721 if (shift==set->digits) { /* removing all */
2723 res->digits=1; /* .. */
2726 /* first remove leading digits if necessary */
2727 if (res->digits+shift>set->digits) {
2728 decDecap(res, res->digits+shift-set->digits);
2729 /* that updated res->digits; may have gone to 1 (for a */
2732 if (res->digits>1 || *res->lsu) /* if non-zero.. */
2733 res->digits=decShiftToMost(res->lsu, res->digits, shift);
2737 if (-shift>=res->digits) { /* discarding all */
2739 res->digits=1; /* .. */
2742 decShiftToLeast(res->lsu, D2U(res->digits), -shift);
2743 res->digits-=(-shift);
2762 /* C must have space for set->digits digits. */
2858 /* buffer for temporary variable, up to 3 digits */
2870 if (rhs->digits>set->digits) {
2918 workp=MAXI(set->digits+1, rhs->digits); /* actual rounding precision */
2922 needbytes=sizeof(decNumber)+(D2U(rhs->digits)-1)*sizeof(Unit);
2944 exp=f->exponent+f->digits; /* adjusted to Hull rules */
2945 f->exponent=-(f->digits); /* to range */
2956 workset.digits=workp; /* p for initial calculation */
2957 t->bits=0; t->digits=3;
2958 a->bits=0; a->digits=3;
3002 workset.digits=3; /* initial p */
3003 for (; workset.digits<maxp;) {
3005 workset.digits=MINI(workset.digits*2-2, maxp);
3013 /* Here, 0.1 <= a < 1 [Hull], and a has maxp digits */
3042 /* Here workset.digits=maxp and t=0.5, and a->digits determines */
3044 workset.digits--; /* maxp-1 is OK now */
3045 t->exponent=-a->digits-1; /* make 0.5 ulp */
3088 /* digits, so this is the only (relatively rare) condition that */
3090 if (b->digits*2-1 > workp) { /* cannot fit */
3109 Int maxexp=set->emax-set->digits+1;
3120 decShiftToLeast(a->lsu, D2U(a->digits), todrop);
3122 a->digits-=todrop; /* new length */
3132 Int ae=rhs->exponent+rhs->digits-1; /* adjusted exponent */
3172 /* C must have space for set->digits digits. */
3203 /* the digits setting is ignored. The Exact version will signal */
3227 workset.digits=rhs->digits; /* no length rounding */
3258 /* C must have space for set->digits digits. */
3268 Int msudigs; /* digits in res msu */
3282 msua=ua+D2U(lhs->digits)-1; /* -> msu of lhs */
3283 msub=ub+D2U(rhs->digits)-1; /* -> msu of rhs */
3284 msuc=uc+D2U(set->digits)-1; /* -> msu of result */
3285 msudigs=MSUDIGITS(set->digits); /* [faster than remainder] */
3311 res->digits=decGetDigits(res->lsu, uc-res->lsu);
3395 dest->digits=src->digits;
3397 if (src->digits>DECDPUN) { /* more Units to come */
3403 smsup=src->lsu+D2U(src->digits); /* -> source msu+1 */
3417 /* C must have space for set->digits digits. */
3438 /* C must have space for set->digits digits. */
3460 /* C must have space for set->digits digits. */
3479 /* bcd is the uInt array that will receive dn->digits BCD bytes, */
3483 /* bcd must have at least dn->digits bytes. No error is possible; if */
3484 /* dn is a NaN or Infinite, digits must be 1 and the coefficient 0. */
3487 uByte *ub=bcd+dn->digits-1; /* -> lsd */
3513 /* n is the number of digits in the source BCD array (bcd) */
3516 /* dn must have space for at least n digits. No error is possible; */
3521 Unit *up=dn->lsu+D2U(dn->digits)-1; /* -> msu [target pointer] */
3527 /* calculate how many digits in msu, and hence first cut */
3530 *up=0; /* will take <=DECDPUN digits */
3532 cut=DECDPUN; /* next Unit has all digits */
3535 dn->digits=n; /* set digit count */
3554 ae=dn->exponent+dn->digits-1; /* adjusted exponent */
3574 ae=dn->exponent+dn->digits-1; /* adjusted exponent */
3625 dn->digits=1;
3641 /* string must be at least dn->digits+14 characters long */
3653 Int pre; /* digits before the '.' */
3654 Int cut; /* for counting digits in a Unit */
3656 const Unit *up=dn->lsu+D2U(dn->digits)-1; /* -> msu [input pointer] */
3683 if (exp!=0 || (*dn->lsu==0 && dn->digits==1)) return;
3687 /* calculate how many digits in msu, and hence first cut */
3688 cut=MSUDIGITS(dn->digits); /* [faster than remainder] */
3693 u=*up; /* contains DECDPUN digits to lay out */
3695 cut=DECDPUN-1; /* next Unit has all digits */
3701 pre=dn->digits+exp; /* digits before '.' */
3704 e=exp+dn->digits-1; /* calculate E value */
3731 /* lay out the digits of the coefficient, adding 0s and . as needed */
3737 if (up==dn->lsu) break; /* out of input digits (pre>digits) */
3744 if (n<dn->digits) { /* more to come, after '.' */
3748 if (up==dn->lsu) break; /* out of input digits */
3764 if (up==dn->lsu) break; /* out of input digits */
3809 /* C must have space for set->digits digits. */
3814 /* -- a digits+1 calculation is needed because the numbers are */
3815 /* unaligned and span more than set->digits digits */
3816 /* -- a carry to digits+1 digits looks possible */
3850 Int reqdigits=set->digits; /* local copy; requested DIGITS */
3861 if (lhs->digits>reqdigits) {
3866 if (rhs->digits>reqdigits) {
3922 if ((res->digits-adjust)>set->digits) {
3923 adjust=res->digits-set->digits; /* to fit exactly */
3926 res->digits=decShiftToMost(res->lsu, res->digits, -adjust);
3949 if ((res->digits-adjust)>set->digits) {
3950 adjust=res->digits-set->digits; /* to fit exactly */
3953 res->digits=decShiftToMost(res->lsu, res->digits, -adjust);
3972 && rhs->digits<=DECDPUN
3974 && rhs->exponent<=set->emax-set->digits+1 /* [could clamp] */
3975 && rhs->digits<=reqdigits
3976 && lhs->digits<=reqdigits) {
3981 && (lhs->digits>=DECDPUN || /* .. and no digits-count change */
3982 partial<(Int)powers[lhs->digits])) { /* .. */
3994 /* this could have reduced digits [but result>0] */
3995 res->digits=decGetDigits(res->lsu, D2U(res->digits));
4027 /* If, after pad, rhs would be longer than lhs by digits+1 or */
4030 if (rhs->digits+padding > lhs->digits+reqdigits+1) {
4033 Int shift=reqdigits-rhs->digits; /* left shift needed */
4040 res->digits=decShiftToMost(res->lsu, res->digits, shift);
4048 /* LHS digits may affect result */
4056 maxdigits=rhs->digits+padding; /* virtual length of RHS */
4057 if (lhs->digits>maxdigits) maxdigits=lhs->digits;
4067 /* buffer needed, choose it; units for maxdigits digits will be */
4085 decDumpAr('A', lhs->lsu, D2U(lhs->digits));
4086 decDumpAr('B', rhs->lsu, D2U(rhs->digits));
4091 U_ASSERT(rhs->digits > 0);
4092 U_ASSERT(lhs->digits > 0);
4093 res->digits=decUnitAddSub(lhs->lsu, D2U(lhs->digits),
4094 rhs->lsu, D2U(rhs->digits),
4096 *DECDPUN; /* [units -> digits] */
4097 if (res->digits<0) { /* borrowed... */
4098 res->digits=-res->digits;
4102 decDumpAr('+', acc, D2U(res->digits));
4115 if (res->digits>reqdigits)
4116 res->digits=decGetDigits(acc, D2U(res->digits));
4117 decSetCoeff(res, set, acc, res->digits, &residue, status);
4122 /* numbers fit in DECDPUN digits and are padding with a */
4126 if (res->digits<maxdigits) {
4127 *(acc+D2U(res->digits))=0; /* ensure leading 0 is there */
4128 res->digits=maxdigits;
4134 if (res->digits>reqdigits) {
4135 res->digits=decGetDigits(acc, D2U(res->digits));
4136 if (res->digits<maxdigits) res->digits=maxdigits;
4139 decSetCoeff(res, set, acc, res->digits, &residue, status);
4151 res->digits=decGetDigits(res->lsu, D2U(res->digits));
4193 /* C must have space for set->digits digits. */
4212 /* Do until (have=digits+1 OR residue=0) */
4241 /* Two working buffers are needed during the division; one (digits+ */
4242 /* 1) to accumulate the result, and the other (up to 2*digits+1) for */
4261 Int accdigits; /* count of digits accumulated */
4275 Int var1initpad=0; /* var1 initial padding (digits) */
4280 Int reqdigits=set->digits; /* requested DIGITS */
4300 if (lhs->digits>reqdigits) {
4305 if (rhs->digits>reqdigits) {
4346 res->exponent=set->emin-set->digits+1;
4403 exponent=(lhs->exponent+lhs->digits)-(rhs->exponent+rhs->digits);
4449 /* (rhs->digits+reqdigits-1) -- to allow full slide to right */
4450 /* or (lhs->digits) -- to allow for long lhs */
4456 maxdigits=rhs->digits+reqdigits-1;
4457 if (lhs->digits>maxdigits) maxdigits=lhs->digits;
4477 source=lhs->lsu+D2U(lhs->digits)-1; /* msu of input array */
4483 var2units=D2U(rhs->digits); /* rhs actual length (units) */
4501 /* [This is actually done by counting the digits and negating, as */
4513 /* save the initial 'false' padding of var1, in digits */
4514 var1initpad=(var1units-D2U(lhs->digits))*DECDPUN;
4536 accdigits=0; /* .. or digits */
4537 accnext=acc+acclength-1; /* -> msu of acc [NB: allows digits+1] */
4605 /* account exactly for the new digits */
4613 if (accdigits>reqdigits) break; /* have enough digits */
4617 /* or divideInteger and still not enough digits yet) */
4637 /* accunits is the number of digits collected in acc */
4716 /* calculate the unused zero digits. This is the smaller of: */
4723 /* shift var1 the requested amount, and adjust its digits */
4748 compare=decUnitCompare(accnext, tarunits, rhs->lsu, D2U(rhs->digits),
4781 quotdigits-=DECDPUN; /* checked those digits */
4796 rhs->lsu, D2U(rhs->digits),
4798 accdigits=decGetDigits(accnext, accunits); /* count digits exactly */
4842 /* C must have space for set->digits digits. */
4889 #define FASTDIGS 9 /* digits in base */
4954 if (lhs->digits<rhs->digits) { /* swap... */
4964 if (lhs->digits>set->digits) {
4969 if (rhs->digits>set->digits) {
4979 /* use the fast path if there are enough digits in the shorter */
4982 if (rhs->digits>NEEDTWO) { /* use fastpath... */
4984 ilhs=(lhs->digits+FASTDIGS-1)/FASTDIGS; /* [ceiling] */
4985 irhs=(rhs->digits+FASTDIGS-1)/FASTDIGS; /* .. */
5007 /* if the given numbers have less digits than DEC_MAX_DIGITS. */
5027 for (count=lhs->digits, cup=lhs->lsu, lip=zlhi; count>0; lip++)
5032 for (count=rhs->digits, cup=rhs->lsu, rip=zrhi; count>0; rip++)
5049 /* add -- every 162 digits. Similarly, when FASTDIGS=8, the */
5052 /* resolution occurs only every 14752 digits. Hence for common */
5109 needbytes=(D2U(lhs->digits)+D2U(rhs->digits))*sizeof(Unit);
5124 madlength=D2U(lhs->digits); /* this won't change */
5125 mermsup=rhs->lsu+D2U(rhs->digits); /* -> msu+1 of multiplier */
5153 res->digits=decGetDigits(acc, accunits); /* count digits exactly */
5167 decSetCoeff(res, set, acc, res->digits, &residue, status);
5192 /* C must have space for set->digits digits. status is updated but */
5197 /* digits, emax, and -emin in the context must be less than */
5279 /* the working precision will be no more than set->digits+8+1 */
5291 /* decNumber for the divisor term; this needs at most 9 digits */
5325 /* set->digits-1 zeros between the decimal point and the digit, */
5328 /* 1.0000001. Hence, tiny will be 0.0000004 if digits=7 and x>0 */
5329 /* or 0.00000004 if digits=7 and x<0. If RHS not larger than */
5333 d->exponent=-set->digits; /* * 10**(-d) */
5340 Int shift=set->digits-1;
5343 res->digits=decShiftToMost(res->lsu, 1, shift);
5358 h=rhs->exponent+rhs->digits;
5375 Int maxlever=(rhs->digits>8?1:0);
5381 /* Apply as much as possible, up to a MAXLEVER digits, which */
5384 /* increases to compensate for the "constant digits at the */
5387 Int use=-rhs->digits-lever; /* exponent to use for RHS */
5396 needbytes=sizeof(decNumber)+(D2U(rhs->digits)-1)*sizeof(Unit);
5416 /* this is set->digits+h+2. However, if x is 'over-precise' we */
5417 /* need to allow for all its digits to potentially participate */
5418 /* (consider an x where all the excess digits are 9s) so in */
5419 /* this case use x->digits+h+2 */
5420 p=MAXI(x->digits, set->digits)+h+2; /* [h<=8] */
5425 /* the accumulator needs to be able to hold 2p digits so that */
5436 /* the term needs to be able to hold p digits (which is */
5437 /* guaranteed to be larger than x->digits, so the initial copy */
5439 /* calculation below, which needs an extra two digits */
5458 aset.digits=p*2; /* double */
5460 tset.digits=p;
5462 /* [dset.digits=16, etc., are sufficient] */
5475 /* if rounded to p digits, which is when its value is smaller */
5476 /* than the accumulator by p+1 digits. There must also be */
5478 if (((a->digits+a->exponent)>=(t->digits+t->exponent+p+1))
5479 && (a->digits>=p)) break;
5487 (LI)iterations, (LI)*status, (LI)p, (LI)x->digits);
5497 aset.digits=p+2; /* sufficient precision */
5498 /* avoid the overhead and many extra digits of decNumberPower */
5522 aset.digits=set->digits; /* [use default rounding] */
5570 /* C must have space for set->digits digits. */
5580 /* digits, emax, and -emin in the context must be less than */
5677 if (rhs->exponent==0 && set->digits<=40) {
5679 if (rhs->lsu[0]==0 && rhs->lsu[1]==1 && rhs->digits==2) { /* ln(10) */
5681 if (rhs->lsu[0]==10 && rhs->digits==2) { /* ln(10) */
5688 if (rhs->lsu[0]==2 && rhs->digits==1) { /* ln(2) */
5698 /* the rhs is 'over-precise' then allow for all its digits to */
5700 /* digits are 9s) so in this case use rhs->digits+2. */
5701 p=MAXI(rhs->digits, MAXI(set->digits, 7))+2;
5705 /* be able to hold p digits, and the adjustment up to */
5706 /* rhs->digits+p digits. They are also made big enough for 16 */
5707 /* digits so that they can be used for calculating the initial */
5717 pp=p+rhs->digits;
5733 /* table (see above) indexed by the first two digits of f, */
5737 r=rhs->exponent+rhs->digits; /* 'normalised' exponent */
5742 /* now get top two digits of rhs into b by simple truncate and */
5745 aset.digits=2; aset.round=DEC_ROUND_DOWN;
5754 aset.digits=16; aset.round=DEC_ROUND_HALF_EVEN; /* restore */
5756 /* the initial estimate is now in a, with up to 4 digits correct. */
5772 /* for each iteration double the number of digits to calculate, */
5777 aset.digits=pp; /* working context */
5778 bset.digits=pp+rhs->digits; /* wider context */
5797 /* result by >=0.5 ulp (at the requested digits), which */
5799 /* set->digits+1 digits (or it is zero) -- this is a looser */
5805 (a->digits+a->exponent)>=(b->digits+b->exponent+set->digits+1)) {
5806 if (a->digits==p) break;
5823 aset.digits=pp; /* working context */
5824 bset.digits=pp+rhs->digits; /* wider context */
5831 (LI)iterations, (LI)*status, (LI)p, (LI)rhs->digits);
5837 aset.digits=set->digits; /* [use default rounding] */
5868 /* C must have space for set->digits digits. */
5881 Int reqdigits=set->digits; /* requested DIGITS */
5894 if (lhs->digits>reqdigits) {
5899 if (rhs->digits>reqdigits) { /* [this only checks lostDigits] */
5952 if ((lhs->digits-adjust)>reqdigits) {
5959 /* digits, and must round as it does so */
5962 workset.digits=lhs->digits-adjust; /* set requested length */
5971 /* set->digits==3 */
5972 if (res->digits==reqdigits) { /* cannot shift by 1 */
5977 res->digits=decShiftToMost(res->lsu, res->digits, 1); /* shift */
5986 /* digits, by adding zero or more trailing zeros; this is */
5991 res->digits=decShiftToMost(res->lsu, res->digits, -adjust);
5999 if (res->exponent>set->emax-res->digits+1) { /* too big */
6040 /* C must have space for one digit for COMPARE or set->digits for */
6064 if (lhs->digits>set->digits) {
6069 if (rhs->digits>set->digits) {
6107 result=decUnitCompare(lhs->lsu, D2U(lhs->digits),
6108 rhs->lsu, D2U(rhs->digits), 0);
6251 compare=decUnitCompare(lhs->lsu, D2U(lhs->digits),
6252 rhs->lsu, D2U(rhs->digits),
6426 /* here carry is new Unit of digits; it could be +ve or -ve */
6469 /* Can use QUOT10 as carry <= 4 digits */
6511 /* here carry is new Unit of digits; it could be +ve or -ve and */
6655 for (d=0; d<dn->digits-1; d++) { /* [don't strip the final digit] */
6681 Int maxd=set->emax-set->digits+1-dn->exponent;
6687 decShiftToLeast(dn->lsu, D2U(dn->digits), d);
6689 dn->digits-=d; /* new length */
6715 /* decShiftToMost -- shift digits in array towards most significant */
6718 /* digits is the count of digits in use in the array */
6722 /* returns the new length of the integer in the array, in digits */
6727 static Int decShiftToMost(Unit *uar, Int digits, Int shift) {
6732 if (shift==0) return digits; /* [fastpath] nothing to do */
6733 if ((digits+shift)<=DECDPUN) { /* [fastpath] single-unit case */
6735 return digits+shift;
6739 source=uar+D2U(digits)-1; /* where msu comes from */
6746 first=uar+D2U(digits+shift)-1; /* where msu of source will end up */
6767 return digits+shift;
6771 /* decShiftToLeast -- shift digits in array towards least significant */
6775 /* shift is the number of digits to remove from the lsu end; it */
6780 /* Removed digits are discarded (lost). Units not required to hold */
6790 *uar=0; /* all digits cleared gives zero */
6834 /* dn is the number to round (dn->digits is > set->digits) */
6858 +(D2U(set->digits)-1)*sizeof(Unit));
6866 /* If that set Inexact then "lost digits" is raised... */
6878 /* set is the context [used for length (digits) and rounding mode] */
6889 decSetCoeff(dest, set, src->lsu, src->digits, residue, status);
6896 /* It must have space for set->digits digits */
6899 /* len is digits in the source coefficient [may be dn->digits] */
6904 /* reflect the previous residue and the dropped digits. */
6909 /* dn->lsu and len must == dn->digits. */
6911 /* Note that the coefficient length (len) may be < set->digits, and */
6916 /* decSetSubnormal) the value of set->digits may be less than one, */
6920 /* dn->digits, dn->lsu (and as required), and dn->exponent are */
6923 /* DEC_Rounded status is set if any digits are discarded. */
6924 /* DEC_Inexact status is set if any non-zero digits are discarded, or */
6933 Int discard; /* number of digits to discard */
6942 discard=len-set->digits; /* digits to discard */
6943 if (discard<=0) { /* no digits are being discarded */
6950 dn->digits=len; /* set the new length */
6957 /* some digits must be discarded ... */
6974 dn->digits=1; /* .. */
7003 if (set->digits<=0) { /* special for Quantize/Subnormal :-( */
7005 dn->digits=1; /* .. */
7008 count=set->digits; /* now digits to end up with */
7009 dn->digits=count; /* set the new length */
7048 /* quot holds the uncut high-order digits for the current unit */
7049 if (set->digits<=0) { /* special for Quantize/Subnormal :-( */
7051 dn->digits=1; /* .. */
7054 count=set->digits; /* now digits to end up with */
7055 dn->digits=count; /* set the new length */
7084 /* dn is the number, with space for set->digits digits */
7092 /* -1: as 1, but the hidden digits are subtractive, that */
7201 uInt count=dn->digits; /* digits to be checked */
7211 if ((dn->exponent+dn->digits)>set->emax+1) {
7223 /* other digits zero) */
7225 uInt count=dn->digits; /* digits to be checked */
7241 /* dn->exponent, set->digits); */
7242 if (dn->exponent+1==set->emin-set->digits+1) {
7243 if (count==1 && dn->digits==1) *sup=0; /* here 9 -> 0[.9] */
7246 dn->digits--;
7262 decUnitAddSub(dn->lsu, D2U(dn->digits), uarrone, 1, 0, dn->lsu, bump);
7277 /* b. Reducing positive exponents to 0, if would fit in digits */
7292 if (set->digits >= (dn->exponent+dn->digits)) {
7293 dn->digits=decShiftToMost(dn->lsu, dn->digits, dn->exponent);
7320 Int tinyexp=set->emin-dn->digits+1; /* precalculate subnormal boundary */
7357 if (dn->exponent<=set->emax-set->digits+1) return; /* neither needed */
7361 if (dn->exponent>set->emax-dn->digits+1) { /* too big */
7369 shift=dn->exponent-(set->emax-set->digits+1);
7373 dn->digits=decShiftToMost(dn->lsu, dn->digits, shift);
7397 if (set->clamp) emax-=set->digits-1; /* lower if clamping */
7433 /* set is the context [used for digits and emax] */
7439 Int count=set->digits; /* nines to add */
7440 dn->digits=count;
7448 count-=DECDPUN; /* filled those digits */
7451 dn->exponent=set->emax-set->digits+1;
7488 etiny=set->emin-(set->digits-1); /* smallest allowed exponent */
7506 adjust=etiny-dn->exponent; /* calculate digits to remove */
7518 workset.digits=dn->digits-adjust; /* set requested length */
7521 decSetCoeff(dn, &workset, dn->lsu, dn->digits, residue, status);
7531 dn->digits=decShiftToMost(dn->lsu, dn->digits, 1);
7552 /* digits, emax, and -emin in the context must be less than */
7560 if (set->digits>DEC_MAX_MATH
7563 else if ((rhs->digits>DEC_MAX_MATH
7564 || rhs->exponent+rhs->digits>DEC_MAX_MATH+1
7565 || rhs->exponent+rhs->digits<2*(1-DEC_MAX_MATH))
7588 Int got; /* digits (real or not) processed */
7589 Int ilength=dn->digits+dn->exponent; /* integral length */
7592 /* The number must be an integer that fits in 10 digits */
7609 Int count=-dn->exponent; /* digits to discard */
7618 /* slice off fraction digits and check for non-zero */
7628 got=DECDPUN-count; /* number of digits so far */
7634 /* tricky code now, to accumulate up to 9.3 digits */
7666 /* drop is the number of digits to be removed from the left of dn; */
7667 /* this must be <= dn->digits (if equal, the coefficient is */
7670 /* Returns dn; dn->digits will be <= the initial digits less drop */
7671 /* (after removing drop digits there may be leading zero digits */
7672 /* which will also be removed). Only dn->lsu and dn->digits change. */
7677 if (drop>=dn->digits) { /* losing the whole thing */
7679 if (drop>dn->digits)
7680 printf("decDecap called with drop>digits [%ld>%ld]\n",
7681 (LI)drop, (LI)dn->digits);
7684 dn->digits=1;
7687 msu=dn->lsu+D2U(dn->digits-drop)-1; /* -> likely msu */
7688 cut=MSUDIGITS(dn->digits-drop); /* digits to be in use in msu */
7689 if (cut!=DECDPUN) *msu%=powers[cut]; /* clear left digits */
7690 /* that may have left leading zero digits, so do a proper count... */
7691 dn->digits=decGetDigits(dn->lsu, msu-dn->lsu+1);
7749 if (lhs->digits<=set->digits) uprv_decNumberCopy(res, lhs); /* easy */
7755 uresp1=res->lsu+D2U(set->digits);
7757 res->digits=D2U(set->digits)*DECDPUN;
7759 if (res->digits>set->digits) decDecap(res, res->digits-set->digits);
7798 /* decGetDigits -- count digits in a Units array */
7804 /* returns the number of (significant) digits in the array */
7812 Int digits=(len-1)*DECDPUN+1; /* possible digits excluding msu */
7823 if (digits==1) break; /* a zero has one digit */
7824 digits-=DECDPUN; /* adjust for 0 unit */
7829 digits++;
7832 digits++;
7835 digits++;
7837 for (pow=&powers[4]; *up>=*pow; pow++) digits++;
7844 return digits;
7852 /* Shows: sign, exponent, coefficient (msu first), digits */
7873 if (dn->exponent==0 && dn->digits==1 && *dn->lsu==0) {
7881 up=dn->lsu+D2U(dn->digits)-1; /* msu */
7897 printf(" [%ld]\n", (LI)dn->digits);
7963 && (set->digits<1 || set->round>=DEC_ROUND_MAX)) {
7966 printf("Bad context [digits=%ld round=%ld].\n",
7967 (LI)set->digits, (LI)set->round);
8002 Int ae, d, digits; /* .. */
8023 if (dn->digits!=1) {
8025 printf("Digits %ld (not 1) for an infinity.\n", (LI)dn->digits);
8032 decDumpAr('I', dn->lsu, D2U(dn->digits));
8041 if (dn->digits<1 || dn->digits>DECNUMMAXP) {
8043 printf("Digits %ld in number.\n", (LI)dn->digits);
8047 d=dn->digits;
8053 if (dn->digits>1 && *up<powers[d-1]) {
8063 (LI)*up, (LI)dn->digits, (LI)(up-dn->lsu), (LI)maxuint);
8070 /* which are out of the set->emin/set->emax and set->digits range */
8071 /* (just as they can have more digits than set->digits). */
8072 ae=dn->exponent+dn->digits-1; /* adjusted exponent */
8075 digits=DECNUMMAXP;
8076 if (ae<emin-(digits-1)) {
8093 /* decCheckInexact -- check a normal finite inexact result has digits */
8096 /* sets Invalid operation, etc., if some digits are missing */
8103 && (set->digits!=dn->digits) && !(dn->bits & DECSPECIAL)) {
8105 printf("Insufficient digits [%ld] on normal Inexact result.\n",
8106 (LI)dn->digits);
8113 if (dn!=NULL && dn->digits==0) set->status|=DEC_Invalid_operation;