Home | History | Annotate | Download | only in i18n

Lines Matching refs:Unit

167 /*      lsu -- least significant Unit (of coefficient)                */
170 /* msu -- most significant Unit (of coefficient) */
212 static Unit uarrone[1]={1}; /* Unit array of 1, used for incrementing */
222 /* QUOT10 -- macro to return the quotient of unit u divided by 10**n */
251 static Int decGetDigits(Unit *, Int);
263 static void decReverse(Unit *, Unit *);
264 static void decSetCoeff(decNumber *, decContext *, const Unit *,
269 static Int decShiftToLeast(Unit *, Int, Int);
270 static Int decShiftToMost(Unit *, Int, Int);
274 static Int decUnitAddSub(const Unit *, Int, const Unit *, Int, Int,
275 Unit *, Int);
276 static Int decUnitCompare(const Unit *, Int, const Unit *, Int, Int);
335 static void decDumpAr(char, const Unit *, Int);
365 Unit *up; /* work pointer */
369 *up=(Unit)(uin%(DECDPUNMAX+1));
395 const Unit *up; /* .. */
431 const Unit *up; /* .. */
499 Unit *res; /* where result will be built */
500 Unit resbuff[SD2U(DECBUFFER+9)];/* local buffer in case need temporary */
502 Unit *allocres=NULL; /* -> allocated result, iff allocated */
508 Unit *up; /* .. */
659 Int needbytes=D2U(d)*sizeof(Unit);/* bytes needed */
662 allocres=(Unit *)malloc(needbytes);
667 /* res now -> number lsu, buffer, or allocated storage for Unit array */
669 /* Place the coefficient into the selected Unit array */
674 cut=d-(up-res)*DECDPUN; /* digits in top unit */
680 if (cut>0) continue; /* more for this unit */
681 *up=(Unit)out; /* write unit */
682 up--; /* prepare for unit below.. */
686 *up=(Unit)out; /* write lsu */
693 *up=(Unit)((Int)*c-(Int)'0');
804 const Unit *ua, *ub; /* -> operands */
805 const Unit *msua, *msub; /* -> operand msus */
806 Unit *uc, *msuc; /* -> result and its msu */
826 for (; uc<=msuc; ua++, ub++, uc++) { /* Unit loop */
827 Unit a, b; /* extract units */
838 if (a&b&1) *uc=*uc+(Unit)powers[i]; /* effect AND */
850 } /* each unit */
950 needbytes=sizeof(decNumber)+(D2U(lhs->digits)-1)*sizeof(Unit);
964 needbytes=sizeof(decNumber)+(D2U(rhs->digits)-1)*sizeof(Unit);
1143 needbytes=sizeof(decNumber)+(D2U(dcmul.digits)-1)*sizeof(Unit);
1202 const Unit *ua, *msua; /* -> operand and its msu */
1203 Unit *uc, *msuc; /* -> result and its msu */
1219 for (; uc<=msuc; ua++, uc++) { /* Unit loop */
1220 Unit a; /* extract unit */
1228 if ((~a)&1) *uc=*uc+(Unit)powers[i]; /* effect INVERT */
1237 } /* each unit */
1476 needbytes=sizeof(decNumber)+(D2U(p)-1)*sizeof(Unit);
1499 needbytes=sizeof(decNumber)+(D2U(p)-1)*sizeof(Unit);
1820 const Unit *ua, *ub; /* -> operands */
1821 const Unit *msua, *msub; /* -> operand msus */
1822 Unit *uc, *msuc; /* -> result and its msu */
1841 for (; uc<=msuc; ua++, ub++, uc++) { /* Unit loop */
1842 Unit a, b; /* extract units */
1852 if ((a|b)&1) *uc=*uc+(Unit)powers[i]; /* effect OR */
1864 } /* each unit */
2146 needbytes=sizeof(decNumber)+(D2U(aset.digits)-1)*sizeof(Unit);
2498 Unit *msu=res->lsu+D2U(res->digits)-1; /* current msu */
2499 Unit *msumax=res->lsu+D2U(set->digits)-1; /* rotation msu */
2505 /* 1. shift all to least up to one unit to unit-align final */
2513 /* the final msd is in the right place in its Unit [any */
2543 *msumax=(Unit)(save/powers[shift-msudigits]); /* and insert */
2545 +(Unit)(rem*powers[DECDPUN-(shift-msudigits)]); /* .. */
2548 *msumax=*msumax+(Unit)(save*powers[msudigits-shift]); /* [maybe *1] */
2561 *msumax=*msumax+(Unit)(save*powers[msudigits]);
2591 Unit ret=0; /* return value */
2907 needbytes=sizeof(decNumber)+(D2U(rhs->digits)-1)*sizeof(Unit);
2916 needbytes=sizeof(decNumber)+(D2U(maxp)-1)*sizeof(Unit);
3250 const Unit *ua, *ub; /* -> operands */
3251 const Unit *msua, *msub; /* -> operand msus */
3252 Unit *uc, *msuc; /* -> result and its msu */
3271 for (; uc<=msuc; ua++, ub++, uc++) { /* Unit loop */
3272 Unit a, b; /* extract units */
3282 if ((a^b)&1) *uc=*uc+(Unit)powers[i]; /* effect XOR */
3294 } /* each unit */
3383 const Unit *smsup, *s; /* work */
3384 Unit *d; /* .. */
3473 const Unit *up=dn->lsu; /* Unit pointer, -> lsu */
3479 uInt cut=DECDPUN; /* downcounter through unit */
3484 if (cut>0) continue; /* more in this unit */
3506 Unit *up=dn->lsu+D2U(dn->digits)-1; /* -> msu [target pointer] */
3514 for (;up>=dn->lsu; up--) { /* each Unit from msu */
3517 cut=DECDPUN; /* next Unit has all digits */
3639 Int cut; /* for counting digits in a Unit */
3641 const Unit *up=dn->lsu+D2U(dn->digits)-1; /* -> msu [input pointer] */
3677 for (;up>=dn->lsu; up--) { /* each Unit from msu */
3680 cut=DECDPUN-1; /* next Unit has all digits */
3721 if (cut<0) { /* need new Unit */
3732 if (cut<0) { /* need new Unit */
3748 if (cut<0) { /* need new Unit */
3830 Unit *acc; /* accumulator for result */
3831 Unit accbuff[SD2U(DECBUFFER*2+20)]; /* local buffer [*2+20 reduces many */
3834 Unit *allocacc=NULL; /* -> allocated acc buffer, iff allocated */
3954 /* is all in one unit, no operand rounding is needed, and no carry, */
3965 if ((partial<=DECDPUNMAX) /* result fits in unit */
3969 *res->lsu=(Unit)partial; /* [copy could have overwritten RHS] */
3978 *res->lsu=(Unit)partial;
4034 rhsshift=D2U(padding+1)-1; /* this much by Unit shift .. */
4053 /* needed, +1 Unit for carry or borrow */
4056 if (need*sizeof(Unit)>sizeof(accbuff)) {
4058 allocacc=(Unit *)malloc(need*sizeof(Unit));
4181 /* with bi-unit (rather than bi-digit) estimation for each unit */
4206 /* else tops2=msu2plus -- {0, unit 1 of var2} */
4238 Unit accbuff[SD2U(DECBUFFER+DECDPUN+10)]; /* local buffer */
4239 Unit *acc=accbuff; /* -> accumulator array for result */
4240 Unit *allocacc=NULL; /* -> allocated buffer, iff allocated */
4241 Unit *accnext; /* -> where next digit will go */
4246 Unit varbuff[SD2U(DECBUFFER*2+DECDPUN)]; /* buffer for var1 */
4247 Unit *var1=varbuff; /* -> var1 array for long subtraction */
4248 Unit *varalloc=NULL; /* -> allocated buffer, iff used */
4249 Unit *msu1; /* -> msu of var1 */
4251 const Unit *var2; /* -> var2 array */
4252 const Unit *msu2; /* -> msu of var2 */
4261 Unit thisunit; /* current unit being accumulated */
4267 Unit *target; /* work */
4268 const Unit *source; /* .. */
4419 if (acclength*sizeof(Unit)>sizeof(accbuff)) {
4421 allocacc=(Unit *)malloc(acclength*sizeof(Unit));
4442 /* allocate a guard unit above msu1 for REMAINDERNEAR */
4444 if ((var1units+1)*sizeof(Unit)>sizeof(varbuff)) {
4446 varalloc=(Unit *)malloc((var1units+1)*sizeof(Unit));
4457 /* One guard unit was allocated above msu1 for rem=rem+rem in */
4490 /* the result will be Unit-aligned. To do this, shift the var1 */
4495 Unit *u; /* work */
4522 thisunit=0; /* current unit assumed 0 */
4523 /* find the next unit */
4526 /* subtract last time around]. Leave at least one unit. */
4530 if (var1units==var2ulen) { /* unit-by-unit compare needed */
4532 const Unit *pv1, *pv2;
4533 Unit
4559 /* The var2 msu is one unit towards the lsu of the var1 msu, */
4560 /* so only one unit for var2 can be used. */
4565 thisunit=(Unit)(thisunit+mult); /* accumulate */
4584 /* The next unit has been calculated in full; unless it's a */
4607 /* divide and just did the last ('units') unit */
4611 /* Unit power of ten and go for the next digit */
4622 accunits=1; /* show have a unit .. */
4627 /* accnext now -> lowest unit of result */
4639 Unit lsu=*accnext;
4674 Unit *quotlsu; /* for save */
4720 Unit *up; /* .. */
4722 /* 'headroom' of an extra unit and hence enough space) */
4740 Int half; /* half to add to lower unit */
4760 else { /* this is the last Unit */
4858 Unit *acc; /* -> accumulator Unit array */
4861 Unit accbuff[SD2U(DECBUFFER*4+1)]; /* buffer (+1 for DECBUFFER==0, */
4863 const Unit *mer, *mermsup; /* work */
4901 const Unit *cup; /* .. */
4902 Unit *up; /* .. */
5000 acc=(Unit *)zacc; /* -> target Unit array */
5076 *up=(Unit)(item-(part*(DECDPUNMAX+1)));
5079 *up=(Unit)item; up++; /* [final needs no division] */
5088 needbytes=(D2U(lhs->digits)+D2U(rhs->digits))*sizeof(Unit);
5090 allocacc=(Unit *)malloc(needbytes);
5092 acc=(Unit *)allocacc; /* use the allocated space */
5107 /* Here, *mer is the next Unit in the multiplier to use */
5117 /* multiply multiplicand by 10**DECDPUN for next Unit to left */
5129 /* possibly with a leading zero unit; build the decNumber from */
5375 needbytes=sizeof(decNumber)+(D2U(rhs->digits)-1)*sizeof(Unit);
5407 needbytes=sizeof(decNumber)+(D2U(p*2)-1)*sizeof(Unit);
5419 needbytes=sizeof(decNumber)+(D2U(p+2)-1)*sizeof(Unit);
5688 needbytes=sizeof(decNumber)+(D2U(MAXI(p,16))-1)*sizeof(Unit);
5697 needbytes=sizeof(decNumber)+(D2U(MAXI(pp,16))-1)*sizeof(Unit);
6238 /* decUnitCompare -- compare two >=0 integers in Unit arrays */
6240 /* This routine compares A ? B*10**E where A and B are unit arrays */
6244 /* Arg1 is A first Unit (lsu) */
6246 /* Arg3 is B first Unit (lsu) */
6254 static Int decUnitCompare(const Unit *a, Int alength,
6255 const Unit *b, Int blength, Int exp) {
6256 Unit *acc; /* accumulator for result */
6257 Unit accbuff[SD2U(DECBUFFER*2+1)]; /* local buffer */
6258 Unit *allocacc=NULL; /* -> allocated acc buffer, iff allocated */
6260 const Unit *l, *r, *u; /* work */
6266 /* same number of units in both -- need unit-by-unit compare */
6276 /* Unaligned. If one is >1 unit longer than the other, padded */
6288 if (need*sizeof(Unit)>sizeof(accbuff)) {
6289 allocacc=(Unit *)malloc(need*sizeof(Unit));
6312 /* decUnitAddSub -- add or subtract two >=0 integers in Unit arrays */
6324 /* shift), or one Unit longer than that (if a Unit carry occurred). */
6332 /* Arg1 is A first Unit (lsu) */
6334 /* Arg3 is B first Unit (lsu) */
6337 /* Arg6 is C first Unit (lsu) */
6346 /* safe, allowing space if necessary for a one-Unit carry. */
6358 static Int decUnitAddSub(const Unit *a, Int alength,
6359 const Unit *b, Int blength, Int bshift,
6360 Unit *c, Int m) {
6361 const Unit *alsu=a; /* A lsu [need to remember it] */
6362 Unit *clsu=c; /* C ditto */
6363 Unit *minC; /* low water mark for C */
6364 Unit *maxC; /* high water mark for C */
6391 Unit *hold=minC;
6405 /* here carry is new Unit of digits; it could be +ve or -ve */
6407 *c=(Unit)carry;
6414 *c=(Unit)(carry-est*(DECDPUNMAX+1)); /* remainder */
6424 *c=(Unit)(carry-est*(DECDPUNMAX+1));
6432 *c=(Unit)(carry-est*(DECDPUNMAX+1)); /* remainder */
6442 *c=(Unit)(carry-est*(DECDPUNMAX+1));
6451 *c=(Unit)(carry-est*(DECDPUNMAX+1)); /* remainder */
6458 *c=(Unit)(carry-est*(DECDPUNMAX+1));
6463 *c=(Unit)(carry-(DECDPUNMAX+1)); /* [helps additions] */
6468 *c=(Unit)(carry%(DECDPUNMAX+1));
6474 *c=(Unit)(carry%(DECDPUNMAX+1));
6490 /* here carry is new Unit of digits; it could be +ve or -ve and */
6493 *c=(Unit)carry;
6497 /* result for this unit is negative or >DECDPUNMAX */
6501 *c=(Unit)(carry-est*(DECDPUNMAX+1)); /* remainder */
6511 *c=(Unit)(carry-est*(DECDPUNMAX+1));
6519 *c=(Unit)(carry-est*(DECDPUNMAX+1)); /* remainder */
6529 *c=(Unit)(carry-est*(DECDPUNMAX+1));
6537 *c=(Unit)(carry-est*(DECDPUNMAX+1)); /* remainder */
6544 *c=(Unit)(carry-est*(DECDPUNMAX+1));
6548 *c=(Unit)(carry-(DECDPUNMAX+1));
6554 *c=(Unit)(carry%(DECDPUNMAX+1));
6560 *c=(Unit)(carry%(DECDPUNMAX+1));
6569 *c=(Unit)carry; /* place as new unit */
6578 *c=(Unit)add;
6586 /* add an extra unit iff it would be non-zero */
6591 *c=(Unit)(add-carry-1);
6616 Unit *up; /* -> current Unit */
6632 cut=1; /* digit (1-DECDPUN) in Unit */
6633 up=dn->lsu; /* -> current Unit */
6651 if (cut>DECDPUN) { /* need new Unit */
6674 /* decReverse -- reverse a Unit array in place */
6677 /* uhi is the end of the array (highest Unit to include) */
6681 /* digit(s) in each unit are unaffected. */
6683 static void decReverse(Unit *ulo, Unit *uhi) {
6684 Unit temp;
6706 static Int decShiftToMost(Unit *uar, Int digits, Int shift) {
6707 Unit *target, *source, *first; /* work */
6712 if ((digits+shift)<=DECDPUN) { /* [fastpath] single-unit case */
6713 *uar=(Unit)(*uar*powers[shift]);
6721 if (cut==0) { /* unit-boundary case */
6727 /* split the source Unit and accumulate remainder for next */
6736 if (target<=first) *target=(Unit)next; /* write to target iff valid */
6737 next=rem*powers[DECDPUN-cut]; /* save remainder for next Unit */
6741 /* propagate any partial unit to one below and clear the rest */
6743 *target=(Unit)next;
6762 static Int decShiftToLeast(Unit *uar, Int units, Int shift) {
6763 Unit *target, *up; /* work */
6775 if (cut==DECDPUN) { /* unit-boundary case; easy */
6790 *target=(Unit)quot;
6802 *target=(Unit)(*target+rem*powers[DECDPUN-cut]);
6837 +(D2U(set->digits)-1)*sizeof(Unit));
6910 static void decSetCoeff(decNumber *dn, decContext *set, const Unit *lsu,
6913 uInt cut; /* cut point in Unit */
6914 const Unit *up; /* work */
6915 Unit *target; /* .. */
6961 /* the Unit with the first discarded digit. When reach it, extract */
6970 /* here up -> Unit with first discarded digit */
6972 if (cut==DECDPUN-1) { /* unit-boundary case (fast) */
6973 Unit half=(Unit)powers[DECDPUN]>>1;
6990 /* on unit boundary, so shift-down copy loop is simple */
6994 } /* unit-boundary case */
6999 if (cut==0) quot=*up; /* is at bottom of unit */
7000 else /* cut>0 */ { /* it's not at bottom of unit */
7024 /* here: up -> Unit of the array with bottom digit */
7025 /* cut is the division point for each Unit */
7026 /* quot holds the uncut high-order digits for the current unit */
7036 *target=(Unit)quot;
7048 *target=(Unit)(*target+rem*powers[DECDPUN-cut]);
7053 } /* not unit boundary */
7178 Unit *up; /* work */
7182 /* this is the last Unit (the msu) */
7185 *up=(Unit)powers[count-1]; /* here 999 -> 100 etc. */
7194 /* a full unit to check, with more to come */
7202 Unit *up, *sup; /* work */
7206 /* this is the last Unit (the msu) */
7210 *up=(Unit)powers[count]-1; /* here 100 in msu -> 999 */
7212 for (up=up-1; up>=dn->lsu; up--) *up=(Unit)powers[DECDPUN]-1;
7223 *sup=(Unit)powers[count-1]-1; /* here 999.. in msu -> 99.. */
7232 /* a full unit to check, with more to come */
7416 Unit *up; /* work */
7421 if (count>DECDPUN) *up=DECDPUNMAX; /* unit full o'nines */
7423 *up=(Unit)(powers[count]-1);
7565 const Unit *up; /* work */
7588 /* spin up whole units until reach the Unit with the unit digit */
7590 if (*up!=0) return BADINT; /* non-zero Unit to discard */
7617 /* collect any remaining unit(s) */
7653 Unit *msu; /* -> target cut point */
7729 const Unit *ul;
7730 Unit *ur, *uresp1;
7778 /* uar is the Unit array holding the number (this is often an */
7788 static Int decGetDigits(Unit *uar, Int len) {
7789 Unit *up=uar+(len-1); /* -> msu */
7800 if (*up==0) { /* unit is all 0s */
7802 digits-=DECDPUN; /* adjust for 0 unit */
7804 /* found the first (most significant) non-zero Unit */
7835 const Unit *up; /* work */
7881 /* decDumpAr -- display a unit array [debug/check aid] */
7886 static void decDumpAr(char name, const Unit *ar, Int len) {
7978 const Unit *up; /* work */
8040 printf("Bad Unit [%08lx] in %ld-digit number at offset %ld [maxuint %ld].\n",