Lines Matching refs:Unit
167 /* lsu -- least significant Unit (of coefficient) */
170 /* msu -- most significant Unit (of coefficient) */
213 static const Unit uarrone[1]={1}; /* Unit array of 1, used for incrementing */
237 /* QUOT10 -- macro to return the quotient of unit u divided by 10**n */
266 static Int decGetDigits(Unit *, Int);
278 static void decReverse(Unit *, Unit *);
279 static void decSetCoeff(decNumber *, decContext *, const Unit *,
284 static Int decShiftToLeast(Unit *, Int, Int);
285 static Int decShiftToMost(Unit *, Int, Int);
289 static Int decUnitAddSub(const Unit *, Int, const Unit *, Int, Int,
290 Unit *, Int);
291 static Int decUnitCompare(const Unit *, Int, const Unit *, Int, Int);
350 static void decDumpAr(char, const Unit *, Int);
380 Unit *up; /* work pointer */
384 *up=(Unit)(uin%(DECDPUNMAX+1));
410 const Unit *up; /* .. */
446 const Unit *up; /* .. */
514 Unit *res; /* where result will be built */
515 Unit resbuff[SD2U(DECBUFFER+9)];/* local buffer in case need temporary */
517 Unit *allocres=NULL; /* -> allocated result, iff allocated */
523 Unit *up; /* .. */
674 Int needbytes=D2U(d)*sizeof(Unit);/* bytes needed */
677 allocres=(Unit *)malloc(needbytes);
682 /* res now -> number lsu, buffer, or allocated storage for Unit array */
684 /* Place the coefficient into the selected Unit array */
689 cut=d-(up-res)*DECDPUN; /* digits in top unit */
695 if (cut>0) continue; /* more for this unit */
696 *up=(Unit)out; /* write unit */
697 up--; /* prepare for unit below.. */
701 *up=(Unit)out; /* write lsu */
708 *up=(Unit)((Int)*c-(Int)'0');
819 const Unit *ua, *ub; /* -> operands */
820 const Unit *msua, *msub; /* -> operand msus */
821 Unit *uc, *msuc; /* -> result and its msu */
841 for (; uc<=msuc; ua++, ub++, uc++) { /* Unit loop */
842 Unit a, b; /* extract units */
853 if (a&b&1) *uc=*uc+(Unit)powers[i]; /* effect AND */
865 } /* each unit */
965 needbytes=sizeof(decNumber)+(D2U(lhs->digits)-1)*sizeof(Unit);
979 needbytes=sizeof(decNumber)+(D2U(rhs->digits)-1)*sizeof(Unit);
1158 needbytes=sizeof(decNumber)+(D2U(dcmul.digits)-1)*sizeof(Unit);
1217 const Unit *ua, *msua; /* -> operand and its msu */
1218 Unit *uc, *msuc; /* -> result and its msu */
1234 for (; uc<=msuc; ua++, uc++) { /* Unit loop */
1235 Unit a; /* extract unit */
1243 if ((~a)&1) *uc=*uc+(Unit)powers[i]; /* effect INVERT */
1252 } /* each unit */
1491 needbytes=sizeof(decNumber)+(D2U(p)-1)*sizeof(Unit);
1514 needbytes=sizeof(decNumber)+(D2U(p)-1)*sizeof(Unit);
1835 const Unit *ua, *ub; /* -> operands */
1836 const Unit *msua, *msub; /* -> operand msus */
1837 Unit *uc, *msuc; /* -> result and its msu */
1856 for (; uc<=msuc; ua++, ub++, uc++) { /* Unit loop */
1857 Unit a, b; /* extract units */
1867 if ((a|b)&1) *uc=*uc+(Unit)powers[i]; /* effect OR */
1879 } /* each unit */
2161 needbytes=sizeof(decNumber)+(D2U(aset.digits)-1)*sizeof(Unit);
2513 Unit *msu=res->lsu+D2U(res->digits)-1; /* current msu */
2514 Unit *msumax=res->lsu+D2U(set->digits)-1; /* rotation msu */
2520 /* 1. shift all to least up to one unit to unit-align final */
2528 /* the final msd is in the right place in its Unit [any */
2558 *msumax=(Unit)(save/powers[shift-msudigits]); /* and insert */
2560 +(Unit)(rem*powers[DECDPUN-(shift-msudigits)]); /* .. */
2563 *msumax=*msumax+(Unit)(save*powers[msudigits-shift]); /* [maybe *1] */
2576 *msumax=*msumax+(Unit)(save*powers[msudigits]);
2606 Unit ret=0; /* return value */
2922 needbytes=sizeof(decNumber)+(D2U(rhs->digits)-1)*sizeof(Unit);
2931 needbytes=sizeof(decNumber)+(D2U(maxp)-1)*sizeof(Unit);
3265 const Unit *ua, *ub; /* -> operands */
3266 const Unit *msua, *msub; /* -> operand msus */
3267 Unit *uc, *msuc; /* -> result and its msu */
3286 for (; uc<=msuc; ua++, ub++, uc++) { /* Unit loop */
3287 Unit a, b; /* extract units */
3297 if ((a^b)&1) *uc=*uc+(Unit)powers[i]; /* effect XOR */
3309 } /* each unit */
3398 const Unit *smsup, *s; /* work */
3399 Unit *d; /* .. */
3488 const Unit *up=dn->lsu; /* Unit pointer, -> lsu */
3494 uInt cut=DECDPUN; /* downcounter through unit */
3499 if (cut>0) continue; /* more in this unit */
3521 Unit *up=dn->lsu+D2U(dn->digits)-1; /* -> msu [target pointer] */
3529 for (;up>=dn->lsu; up--) { /* each Unit from msu */
3532 cut=DECDPUN; /* next Unit has all digits */
3654 Int cut; /* for counting digits in a Unit */
3656 const Unit *up=dn->lsu+D2U(dn->digits)-1; /* -> msu [input pointer] */
3692 for (;up>=dn->lsu; up--) { /* each Unit from msu */
3695 cut=DECDPUN-1; /* next Unit has all digits */
3736 if (cut<0) { /* need new Unit */
3747 if (cut<0) { /* need new Unit */
3763 if (cut<0) { /* need new Unit */
3845 Unit *acc; /* accumulator for result */
3846 Unit accbuff[SD2U(DECBUFFER*2+20)]; /* local buffer [*2+20 reduces many */
3849 Unit *allocacc=NULL; /* -> allocated acc buffer, iff allocated */
3969 /* is all in one unit, no operand rounding is needed, and no carry, */
3980 if ((partial<=DECDPUNMAX) /* result fits in unit */
3984 *res->lsu=(Unit)partial; /* [copy could have overwritten RHS] */
3993 *res->lsu=(Unit)partial;
4049 rhsshift=D2U(padding+1)-1; /* this much by Unit shift .. */
4068 /* needed, +1 Unit for carry or borrow */
4071 if (need*sizeof(Unit)>sizeof(accbuff)) {
4073 allocacc=(Unit *)malloc(need*sizeof(Unit));
4198 /* with bi-unit (rather than bi-digit) estimation for each unit */
4223 /* else tops2=msu2plus -- {0, unit 1 of var2} */
4255 Unit accbuff[SD2U(DECBUFFER+DECDPUN+10)]; /* local buffer */
4256 Unit *acc=accbuff; /* -> accumulator array for result */
4257 Unit *allocacc=NULL; /* -> allocated buffer, iff allocated */
4258 Unit *accnext; /* -> where next digit will go */
4263 Unit varbuff[SD2U(DECBUFFER*2+DECDPUN)]; /* buffer for var1 */
4264 Unit *var1=varbuff; /* -> var1 array for long subtraction */
4265 Unit *varalloc=NULL; /* -> allocated buffer, iff used */
4266 Unit *msu1; /* -> msu of var1 */
4268 const Unit *var2; /* -> var2 array */
4269 const Unit *msu2; /* -> msu of var2 */
4278 Unit thisunit; /* current unit being accumulated */
4284 Unit *target; /* work */
4285 const Unit *source; /* .. */
4436 if (acclength*sizeof(Unit)>sizeof(accbuff)) {
4438 allocacc=(Unit *)malloc(acclength*sizeof(Unit));
4459 /* allocate a guard unit above msu1 for REMAINDERNEAR */
4461 if ((var1units+1)*sizeof(Unit)>sizeof(varbuff)) {
4463 varalloc=(Unit *)malloc((var1units+1)*sizeof(Unit));
4474 /* One guard unit was allocated above msu1 for rem=rem+rem in */
4507 /* the result will be Unit-aligned. To do this, shift the var1 */
4512 Unit *u; /* work */
4539 unit assumed 0 */
4540 /* find the next unit */
4543 /* subtract last time around]. Leave at least one unit. */
4547 if (var1units==var2ulen) { /* unit-by-unit compare needed */
4549 const Unit *pv1, *pv2;
4550 Unit v2; /* units to compare */
4576 /* The var2 msu is one unit towards the lsu of the var1 msu, */
4577 /* so only one unit for var2 can be used. */
4582 thisunit=(Unit)(thisunit+mult); /* accumulate */
4601 /* The next unit has been calculated in full; unless it's a */
4624 /* divide and just did the last ('units') unit */
4628 /* Unit power of ten and go for the next digit */
4639 accunits=1; /* show have a unit .. */
4644 /* accnext now -> lowest unit of result */
4656 Unit lsu=*accnext;
4691 Unit *quotlsu; /* for save */
4737 Unit *up; /* .. */
4739 /* 'headroom' of an extra unit and hence enough space) */
4757 Int half; /* half to add to lower unit */
4777 else { /* this is the last Unit */
4875 Unit *acc; /* -> accumulator Unit array */
4878 Unit accbuff[SD2U(DECBUFFER*4+1)]; /* buffer (+1 for DECBUFFER==0, */
4880 const Unit *mer, *mermsup; /* work */
4918 const Unit *cup; /* .. */
4919 Unit *up; /* .. */
5021 acc=(Unit *)zacc; /* -> target Unit array */
5097 *up=(Unit)(item-(part*(DECDPUNMAX+1)));
5100 *up=(Unit)item; up++; /* [final needs no division] */
5109 needbytes=(D2U(lhs->digits)+D2U(rhs->digits))*sizeof(Unit);
5111 allocacc=(Unit *)malloc(needbytes);
5113 acc=(Unit *)allocacc; /* use the allocated space */
5128 /* Here, *mer is the next Unit in the multiplier to use */
5138 /* multiply multiplicand by 10**DECDPUN for next Unit to left */
5150 /* possibly with a leading zero unit; build the decNumber from */
5396 needbytes=sizeof(decNumber)+(D2U(rhs->digits)-1)*sizeof(Unit);
5428 needbytes=sizeof(decNumber)+(D2U(p*2)-1)*sizeof(Unit);
5440 needbytes=sizeof(decNumber)+(D2U(p+2)-1)*sizeof(Unit);
5709 needbytes=sizeof(decNumber)+(D2U(MAXI(p,16))-1)*sizeof(Unit);
5718 needbytes=sizeof(decNumber)+(D2U(MAXI(pp,16))-1)*sizeof(Unit);
6259 /* decUnitCompare -- compare two >=0 integers in Unit arrays */
6261 /* This routine compares A ? B*10**E where A and B are unit arrays */
6265 /* Arg1 is A first Unit (lsu) */
6267 /* Arg3 is B first Unit (lsu) */
6275 static Int decUnitCompare(const Unit *a, Int alength,
6276 const Unit *b, Int blength, Int exp) {
6277 Unit *acc; /* accumulator for result */
6278 Unit accbuff[SD2U(DECBUFFER*2+1)]; /* local buffer */
6279 Unit *allocacc=NULL; /* -> allocated acc buffer, iff allocated */
6281 const Unit *l, *r, *u; /* work */
6287 /* same number of units in both -- need unit-by-unit compare */
6297 /* Unaligned. If one is >1 unit longer than the other, padded */
6309 if (need*sizeof(Unit)>sizeof(accbuff)) {
6310 allocacc=(Unit *)malloc(need*sizeof(Unit));
6333 /* decUnitAddSub -- add or subtract two >=0 integers in Unit arrays */
6345 /* shift), or one Unit longer than that (if a Unit carry occurred). */
6353 /* Arg1 is A first Unit (lsu) */
6355 /* Arg3 is B first Unit (lsu) */
6358 /* Arg6 is C first Unit (lsu) */
6367 /* safe, allowing space if necessary for a one-Unit carry. */
6379 static Int decUnitAddSub(const Unit *a, Int alength,
6380 const Unit *b, Int blength, Int bshift,
6381 Unit *c, Int m) {
6382 const Unit *alsu=a; /* A lsu [need to remember it] */
6383 Unit *clsu=c; /* C ditto */
6384 Unit *minC; /* low water mark for C */
6385 Unit *maxC; /* high water mark for C */
6412 Unit *hold=minC;
6426 /* here carry is new Unit of digits; it could be +ve or -ve */
6428 *c=(Unit)carry;
6435 *c=(Unit)(carry-est*(DECDPUNMAX+1)); /* remainder */
6445 *c=(Unit)(carry-est*(DECDPUNMAX+1));
6453 *c=(Unit)(carry-est*(DECDPUNMAX+1)); /* remainder */
6463 *c=(Unit)(carry-est*(DECDPUNMAX+1));
6472 *c=(Unit)(carry-est*(DECDPUNMAX+1)); /* remainder */
6479 *c=(Unit)(carry-est*(DECDPUNMAX+1));
6484 *c=(Unit)(carry-(DECDPUNMAX+1)); /* [helps additions] */
6489 *c=(Unit)(carry%(DECDPUNMAX+1));
6495 *c=(Unit)(carry%(DECDPUNMAX+1));
6511 /* here carry is new Unit of digits; it could be +ve or -ve and */
6514 *c=(Unit)carry;
6518 /* result for this unit is negative or >DECDPUNMAX */
6522 *c=(Unit)(carry-est*(DECDPUNMAX+1)); /* remainder */
6532 *c=(Unit)(carry-est*(DECDPUNMAX+1));
6540 *c=(Unit)(carry-est*(DECDPUNMAX+1)); /* remainder */
6550 *c=(Unit)(carry-est*(DECDPUNMAX+1));
6558 *c=(Unit)(carry-est*(DECDPUNMAX+1)); /* remainder */
6565 *c=(Unit)(carry-est*(DECDPUNMAX+1));
6569 *c=(Unit)(carry-(DECDPUNMAX+1));
6575 *c=(Unit)(carry%(DECDPUNMAX+1));
6581 *c=(Unit)(carry%(DECDPUNMAX+1));
6590 *c=(Unit)carry; /* place as new unit */
6599 *c=(Unit)add;
6607 /* add an extra unit iff it would be non-zero */
6612 *c=(Unit)(add-carry-1);
6637 Unit *up; /* -> current Unit */
6653 cut=1; /* digit (1-DECDPUN) in Unit */
6654 up=dn->lsu; /* -> current Unit */
6672 if (cut>DECDPUN) { /* need new Unit */
6695 /* decReverse -- reverse a Unit array in place */
6698 /* uhi is the end of the array (highest Unit to include) */
6702 /* digit(s) in each unit are unaffected. */
6704 static void decReverse(Unit *ulo, Unit *uhi) {
6705 Unit temp;
6727 static Int decShiftToMost(Unit *uar, Int digits, Int shift) {
6728 Unit *target, *source, *first; /* work */
6733 if ((digits+shift)<=DECDPUN) { /* [fastpath] single-unit case */
6734 *uar=(Unit)(*uar*powers[shift]);
6742 if (cut==0) { /* unit-boundary case */
6748 /* split the source Unit and accumulate remainder for next */
6757 if (target<=first) *target=(Unit)next; /* write to target iff valid */
6758 next=rem*powers[DECDPUN-cut]; /* save remainder for next Unit */
6762 /* propagate any partial unit to one below and clear the rest */
6764 *target=(Unit)next;
6783 static Int decShiftToLeast(Unit *uar, Int units, Int shift) {
6784 Unit *target, *up; /* work */
6796 if (cut==DECDPUN) { /* unit-boundary case; easy */
6811 *target=(Unit)quot;
6823 *target=(Unit)(*target+rem*powers[DECDPUN-cut]);
6858 +(D2U(set->digits)-1)*sizeof(Unit));
6931 static void decSetCoeff(decNumber *dn, decContext *set, const Unit *lsu,
6934 uInt cut; /* cut point in Unit */
6935 const Unit *up; /* work */
6936 Unit *target; /* .. */
6982 /* the Unit with the first discarded digit. When reach it, extract */
6991 /* here up -> Unit with first discarded digit */
6993 if (cut==DECDPUN-1) { /* unit-boundary case (fast) */
6994 Unit half=(Unit)powers[DECDPUN]>>1;
7011 /* on unit boundary, so shift-down copy loop is simple */
7015 } /* unit-boundary case */
7020 if (cut==0) quot=*up; /* is at bottom of unit */
7021 else /* cut>0 */ { /* it's not at bottom of unit */
7046 /* here: up -> Unit of the array with bottom digit */
7047 /* cut is the division point for each Unit */
7048 /* quot holds the uncut high-order digits for the current unit */
7058 *target=(Unit)quot;
7070 *target=(Unit)(*target+rem*powers[DECDPUN-cut]);
7075 } /* not unit boundary */
7200 Unit *up; /* work */
7204 /* this is the last Unit (the msu) */
7207 *up=(Unit)powers[count-1]; /* here 999 -> 100 etc. */
7216 /* a full unit to check, with more to come */
7224 Unit *up, *sup; /* work */
7228 /* this is the last Unit (the msu) */
7232 *up=(Unit)powers[count]-1; /* here 100 in msu -> 999 */
7234 for (up=up-1; up>=dn->lsu; up--) *up=(Unit)powers[DECDPUN]-1;
7245 *sup=(Unit)powers[count-1]-1; /* here 999.. in msu -> 99.. */
7254 /* a full unit to check, with more to come */
7438 Unit *up; /* work */
7443 if (count>DECDPUN) *up=DECDPUNMAX; /* unit full o'nines */
7445 *up=(Unit)(powers[count]-1);
7587 const Unit *up; /* work */
7610 /* spin up whole units until reach the Unit with the unit digit */
7612 if (*up!=0) return BADINT; /* non-zero Unit to discard */
7639 /* collect any remaining unit(s) */
7675 Unit *msu; /* -> target cut point */
7751 const Unit *ul;
7752 Unit *ur, *uresp1;
7800 /* uar is the Unit array holding the number (this is often an */
7810 static Int decGetDigits(Unit *uar, Int len) {
7811 Unit *up=uar+(len-1); /* -> msu */
7822 if (*up==0) { /* unit is all 0s */
7824 digits-=DECDPUN; /* adjust for 0 unit */
7826 /* found the first (most significant) non-zero Unit */
7857 const Unit *up; /* work */
7903 /* decDumpAr -- display a unit array [debug/check aid] */
7908 static void decDumpAr(char name, const Unit *ar, Int len) {
8000 const Unit *up; /* work */
8062 printf("Bad Unit [%08lx] in %ld-digit number at offset %ld [maxuint %ld].\n",