Lines Matching full:unit

159 /*	lsu -- least significant Unit (of coefficient)		      */
162 /* msu -- most significant Unit (of coefficient) */
202 static Unit uarrone[1]={1}; /* Unit array of 1, used for incrementing */
212 /* QUOT10 -- macro to return the quotient of unit u divided by 10**n */
241 static Int decGetDigits(Unit *, Int);
253 static void decReverse(Unit *, Unit *);
254 static void decSetCoeff(decNumber *, decContext *, const Unit *,
259 static Int decShiftToLeast(Unit *, Int, Int);
260 static Int decShiftToMost(Unit *, Int, Int);
264 static Int decUnitAddSub(const Unit *, Int, const Unit *, Int, Int,
265 Unit *, Int);
266 static Int decUnitCompare(const Unit *, Int, const Unit *, Int, Int);
322 static void decDumpAr(char, const Unit *, Int);
352 Unit *up; /* work pointer */ in decNumberFromUInt32()
356 *up=(Unit)(uin%(DECDPUNMAX+1)); in decNumberFromUInt32()
382 const Unit *up; /* .. */ in decNumberToInt32()
418 const Unit *up; /* .. */ in decNumberToUInt32()
454 Unit *up; /* work pointer */ in decNumberFromUInt64()
460 *up = (Unit)(uin % (DECDPUNMAX + 1)); in decNumberFromUInt64()
489 Unit *up; /* work pointer */ in decNumberFromUInt128()
496 *up = (Unit)rem; in decNumberFromUInt128()
521 const Unit *up; /* .. */ in decNumberIntegralToInt64()
562 const Unit *up; /* .. */ in decNumberIntegralToInt128()
657 Unit *res; /* where result will be built */ in decNumberFromString()
658 Unit resbuff[SD2U(DECBUFFER+9)];/* local buffer in case need temporary */ in decNumberFromString()
660 Unit *allocres=NULL; /* -> allocated result, iff allocated */ in decNumberFromString()
666 Unit *up; /* .. */ in decNumberFromString()
817 Int needbytes=D2U(d)*sizeof(Unit);/* bytes needed */ in decNumberFromString()
820 allocres=(Unit *)malloc(needbytes); in decNumberFromString()
825 /* res now -> number lsu, buffer, or allocated storage for Unit array */ in decNumberFromString()
827 /* Place the coefficient into the selected Unit array */ in decNumberFromString()
832 cut=d-(up-res)*DECDPUN; /* digits in top unit */ in decNumberFromString()
838 if (cut>0) continue; /* more for this unit */ in decNumberFromString()
839 *up=(Unit)out; /* write unit */ in decNumberFromString()
840 up--; /* prepare for unit below.. */ in decNumberFromString()
844 *up=(Unit)out; /* write lsu */ in decNumberFromString()
851 *up=(Unit)((Int)*c-(Int)'0'); in decNumberFromString()
962 const Unit *ua, *ub; /* -> operands */ in decNumberAnd()
963 const Unit *msua, *msub; /* -> operand msus */ in decNumberAnd()
964 Unit *uc, *msuc; /* -> result and its msu */ in decNumberAnd()
984 for (; uc<=msuc; ua++, ub++, uc++) { /* Unit loop */ in decNumberAnd()
985 Unit a, b; /* extract units */ in decNumberAnd()
996 if (a&b&1) *uc=*uc+(Unit)powers[i]; /* effect AND */ in decNumberAnd()
1008 } /* each unit */ in decNumberAnd()
1108 needbytes=sizeof(decNumber)+(D2U(lhs->digits)-1)*sizeof(Unit); in decNumberCompareTotalMag()
1122 needbytes=sizeof(decNumber)+(D2U(rhs->digits)-1)*sizeof(Unit); in decNumberCompareTotalMag()
1301 needbytes=sizeof(decNumber)+(D2U(dcmul.digits)-1)*sizeof(Unit); in decNumberFMA()
1360 const Unit *ua, *msua; /* -> operand and its msu */ in decNumberInvert()
1361 Unit *uc, *msuc; /* -> result and its msu */ in decNumberInvert()
1377 for (; uc<=msuc; ua++, uc++) { /* Unit loop */ in decNumberInvert()
1378 Unit a; /* extract unit */ in decNumberInvert()
1386 if ((~a)&1) *uc=*uc+(Unit)powers[i]; /* effect INVERT */ in decNumberInvert()
1395 } /* each unit */ in decNumberInvert()
1630 needbytes=sizeof(decNumber)+(D2U(p)-1)*sizeof(Unit); in decNumberLog10()
1653 needbytes=sizeof(decNumber)+(D2U(p)-1)*sizeof(Unit); in decNumberLog10()
1970 const Unit *ua, *ub; /* -> operands */ in decNumberOr()
1971 const Unit *msua, *msub; /* -> operand msus */ in decNumberOr()
1972 Unit *uc, *msuc; /* -> result and its msu */ in decNumberOr()
1991 for (; uc<=msuc; ua++, ub++, uc++) { /* Unit loop */ in decNumberOr()
1992 Unit a, b; /* extract units */ in decNumberOr()
2002 if ((a|b)&1) *uc=*uc+(Unit)powers[i]; /* effect OR */ in decNumberOr()
2014 } /* each unit */ in decNumberOr()
2296 needbytes=sizeof(decNumber)+(D2U(aset.digits)-1)*sizeof(Unit); in decNumberPower()
2647 Unit *msu=res->lsu+D2U(res->digits)-1; /* current msu */ in decNumberRotate()
2648 Unit *msumax=res->lsu+D2U(set->digits)-1; /* rotation msu */ in decNumberRotate()
2654 /* 1. shift all to least up to one unit to unit-align final */ in decNumberRotate()
2662 /* the final msd is in the right place in its Unit [any */ in decNumberRotate()
2692 *msumax=(Unit)(save/powers[shift-msudigits]); /* and insert */ in decNumberRotate()
2694 +(Unit)(rem*powers[DECDPUN-(shift-msudigits)]); /* .. */ in decNumberRotate()
2697 *msumax=*msumax+(Unit)(save*powers[msudigits-shift]); /* [maybe *1] */ in decNumberRotate()
2710 *msumax=*msumax+(Unit)(save*powers[msudigits]); in decNumberRotate()
2740 Unit ret=0; /* return value */ in decNumberSameQuantum()
3051 needbytes=sizeof(decNumber)+(D2U(rhs->digits)-1)*sizeof(Unit); in decNumberSquareRoot()
3060 needbytes=sizeof(decNumber)+(D2U(maxp)-1)*sizeof(Unit); in decNumberSquareRoot()
3384 const Unit *ua, *ub; /* -> operands */ in decNumberXor()
3385 const Unit *msua, *msub; /* -> operand msus */ in decNumberXor()
3386 Unit *uc, *msuc; /* -> result and its msu */ in decNumberXor()
3405 for (; uc<=msuc; ua++, ub++, uc++) { /* Unit loop */ in decNumberXor()
3406 Unit a, b; /* extract units */ in decNumberXor()
3416 if ((a^b)&1) *uc=*uc+(Unit)powers[i]; /* effect XOR */ in decNumberXor()
3428 } /* each unit */ in decNumberXor()
3517 const Unit *smsup, *s; /* work */ in decNumberCopy()
3518 Unit *d; /* .. */ in decNumberCopy()
3607 const Unit *up=dn->lsu; /* Unit pointer, -> lsu */ in decNumberGetBCD()
3613 uInt cut=DECDPUN; /* downcounter through unit */ in decNumberGetBCD()
3618 if (cut>0) continue; /* more in this unit */ in decNumberGetBCD()
3640 Unit *up = dn->lsu + D2U(n) - 1; /* -> msu [target pointer] */ in decNumberSetBCD()
3648 for (;up>=dn->lsu; up--) { /* each Unit from msu */ in decNumberSetBCD()
3651 cut=DECDPUN; /* next Unit has all digits */ in decNumberSetBCD()
3772 Int cut; /* for counting digits in a Unit */ in decToString()
3774 const Unit *up=dn->lsu+D2U(dn->digits)-1; /* -> msu [input pointer] */ in decToString()
3810 for (;up>=dn->lsu; up--) { /* each Unit from msu */ in decToString()
3813 cut=DECDPUN-1; /* next Unit has all digits */ in decToString()
3854 if (cut<0) { /* need new Unit */ in decToString()
3865 if (cut<0) { /* need new Unit */ in decToString()
3881 if (cut<0) { /* need new Unit */ in decToString()
3963 Unit *acc; /* accumulator for result */ in decAddOp()
3964 Unit accbuff[SD2U(DECBUFFER*2+20)]; /* local buffer [*2+20 reduces many */ in decAddOp()
3967 Unit *allocacc=NULL; /* -> allocated acc buffer, iff allocated */ in decAddOp()
4087 /* is all in one unit, no operand rounding is needed, and no carry, */ in decAddOp()
4098 if ((partial<=DECDPUNMAX) /* result fits in unit */ in decAddOp()
4102 *res->lsu=(Unit)partial; /* [copy could have overwritten RHS] */ in decAddOp()
4111 *res->lsu=(Unit)partial; in decAddOp()
4167 rhsshift=D2U(padding+1)-1; /* this much by Unit shift .. */ in decAddOp()
4186 /* needed, +1 Unit for carry or borrow */ in decAddOp()
4189 if (need*sizeof(Unit)>sizeof(accbuff)) { in decAddOp()
4191 allocacc=(Unit *)malloc(need*sizeof(Unit)); in decAddOp()
4314 /* with bi-unit (rather than bi-digit) estimation for each unit */
4339 /* else tops2=msu2plus -- {0, unit 1 of var2} */
4371 Unit accbuff[SD2U(DECBUFFER+DECDPUN+10)]; /* local buffer */ in decDivideOp()
4372 Unit *acc=accbuff; /* -> accumulator array for result */ in decDivideOp()
4373 Unit *allocacc=NULL; /* -> allocated buffer, iff allocated */ in decDivideOp()
4374 Unit *accnext; /* -> where next digit will go */ in decDivideOp()
4379 Unit varbuff[SD2U(DECBUFFER*2+DECDPUN)*sizeof(Unit)]; /* buffer for var1 */ in decDivideOp()
4380 Unit *var1=varbuff; /* -> var1 array for long subtraction */ in decDivideOp()
4381 Unit *varalloc=NULL; /* -> allocated buffer, iff used */ in decDivideOp()
4382 Unit *msu1; /* -> msu of var1 */ in decDivideOp()
4384 const Unit *var2; /* -> var2 array */ in decDivideOp()
4385 const Unit *msu2; /* -> msu of var2 */ in decDivideOp()
4394 Unit thisunit; /* current unit being accumulated */ in decDivideOp()
4400 Unit *target; /* work */ in decDivideOp()
4401 const Unit *source; /* .. */ in decDivideOp()
4552 if (acclength*sizeof(Unit)>sizeof(accbuff)) { in decDivideOp()
4554 allocacc=(Unit *)malloc(acclength*sizeof(Unit)); in decDivideOp()
4575 /* allocate a guard unit above msu1 for REMAINDERNEAR */ in decDivideOp()
4577 if ((var1units+1)*sizeof(Unit)>sizeof(varbuff)) { in decDivideOp()
4579 varalloc=(Unit *)malloc((var1units+1)*sizeof(Unit)); in decDivideOp()
4590 /* One guard unit was allocated above msu1 for rem=rem+rem in */ in decDivideOp()
4623 /* the result will be Unit-aligned. To do this, shift the var1 */ in decDivideOp()
4628 Unit *u; /* work */ in decDivideOp()
4655 thisunit=0; /* current unit assumed 0 */ in decDivideOp()
4656 /* find the next unit */ in decDivideOp()
4659 /* subtract last time around]. Leave at least one unit. */ in decDivideOp()
4663 if (var1units==var2ulen) { /* unit-by-unit compare needed */ in decDivideOp()
4665 const Unit *pv1, *pv2; in decDivideOp()
4666 Unit v2; /* units to compare */ in decDivideOp()
4692 /* The var2 msu is one unit towards the lsu of the var1 msu, */ in decDivideOp()
4693 /* so only one unit for var2 can be used. */ in decDivideOp()
4698 thisunit=(Unit)(thisunit+mult); /* accumulate */ in decDivideOp()
4717 /* The next unit has been calculated in full; unless it's a */ in decDivideOp()
4740 /* divide and just did the last ('units') unit */ in decDivideOp()
4744 /* Unit power of ten and go for the next digit */ in decDivideOp()
4755 accunits=1; /* show have a unit .. */ in decDivideOp()
4760 /* accnext now -> lowest unit of result */ in decDivideOp()
4772 Unit lsu=*accnext; in decDivideOp()
4807 Unit *quotlsu; /* for save */ in decDivideOp()
4853 Unit *up; /* .. */ in decDivideOp()
4855 /* 'headroom' of an extra unit and hence enough space) */ in decDivideOp()
4873 Int half; /* half to add to lower unit */ in decDivideOp()
4893 else { /* this is the last Unit */ in decDivideOp()
4991 Unit *acc; /* -> accumulator Unit array */ in decMultiplyOp()
4994 Unit accbuff[SD2U(DECBUFFER*4+1)]; /* buffer (+1 for DECBUFFER==0, */ in decMultiplyOp()
4996 const Unit *mer, *mermsup; /* work */ in decMultiplyOp()
5034 const Unit *cup; /* .. */ in decMultiplyOp()
5035 Unit *up; /* .. */ in decMultiplyOp()
5133 acc=(Unit *)zacc; /* -> target Unit array */ in decMultiplyOp()
5209 *up=(Unit)(item-(part*(DECDPUNMAX+1))); in decMultiplyOp()
5212 *up=(Unit)item; up++; /* [final needs no division] */ in decMultiplyOp()
5221 needbytes=(D2U(lhs->digits)+D2U(rhs->digits))*sizeof(Unit); in decMultiplyOp()
5223 allocacc=(Unit *)malloc(needbytes); in decMultiplyOp()
5225 acc=(Unit *)allocacc; /* use the allocated space */ in decMultiplyOp()
5240 /* Here, *mer is the next Unit in the multiplier to use */ in decMultiplyOp()
5250 /* multiply multiplicand by 10**DECDPUN for next Unit to left */ in decMultiplyOp()
5262 /* possibly with a leading zero unit; build the decNumber from */ in decMultiplyOp()
5508 needbytes=sizeof(decNumber)+(D2U(rhs->digits)-1)*sizeof(Unit); in decExpOp()
5540 needbytes=sizeof(decNumber)+(D2U(p*2)-1)*sizeof(Unit); in decExpOp()
5552 needbytes=sizeof(decNumber)+(D2U(p+2)-1)*sizeof(Unit); in decExpOp()
5818 needbytes=sizeof(decNumber)+(D2U(MAXI(p,16))-1)*sizeof(Unit);
5827 needbytes=sizeof(decNumber)+(D2U(MAXI(pp,16))-1)*sizeof(Unit);
6365 /* decUnitCompare -- compare two >=0 integers in Unit arrays */
6367 /* This routine compares A ? B*10**E where A and B are unit arrays */
6371 /* Arg1 is A first Unit (lsu) */
6373 /* Arg3 is B first Unit (lsu) */
6381 static Int decUnitCompare(const Unit *a, Int alength,
6382 const Unit *b, Int blength, Int exp) {
6383 Unit *acc; /* accumulator for result */
6384 Unit accbuff[SD2U(DECBUFFER*2+1)]; /* local buffer */
6385 Unit *allocacc=NULL; /* -> allocated acc buffer, iff allocated */
6387 const Unit *l, *r, *u; /* work */
6393 /* same number of units in both -- need unit-by-unit compare */
6403 /* Unaligned. If one is >1 unit longer than the other, padded */
6415 if (need*sizeof(Unit)>sizeof(accbuff)) {
6416 allocacc=(Unit *)malloc(need*sizeof(Unit));
6439 /* decUnitAddSub -- add or subtract two >=0 integers in Unit arrays */
6451 /* shift), or one Unit longer than that (if a Unit carry occurred). */
6459 /* Arg1 is A first Unit (lsu) */
6461 /* Arg3 is B first Unit (lsu) */
6464 /* Arg6 is C first Unit (lsu) */
6473 /* safe, allowing space if necessary for a one-Unit carry. */
6485 static Int decUnitAddSub(const Unit *a, Int alength,
6486 const Unit *b, Int blength, Int bshift,
6487 Unit *c, Int m) {
6488 const Unit *alsu=a; /* A lsu [need to remember it] */
6489 Unit *clsu=c; /* C ditto */
6490 Unit *minC; /* low water mark for C */
6491 Unit *maxC; /* high water mark for C */
6518 Unit *hold=minC;
6532 /* here carry is new Unit of digits; it could be +ve or -ve */
6534 *c=(Unit)carry;
6541 *c=(Unit)(carry-est*(DECDPUNMAX+1)); /* remainder */
6551 *c=(Unit)(carry-est*(DECDPUNMAX+1));
6559 *c=(Unit)(carry-est*(DECDPUNMAX+1)); /* remainder */
6569 *c=(Unit)(carry-est*(DECDPUNMAX+1));
6578 *c=(Unit)(carry-est*(DECDPUNMAX+1)); /* remainder */
6585 *c=(Unit)(carry-est*(DECDPUNMAX+1));
6590 *c=(Unit)(carry-(DECDPUNMAX+1)); /* [helps additions] */
6595 *c=(Unit)(carry%(DECDPUNMAX+1));
6601 *c=(Unit)(carry%(DECDPUNMAX+1));
6617 /* here carry is new Unit of digits; it could be +ve or -ve and */
6620 *c=(Unit)carry;
6624 /* result for this unit is negative or >DECDPUNMAX */
6628 *c=(Unit)(carry-est*(DECDPUNMAX+1)); /* remainder */
6638 *c=(Unit)(carry-est*(DECDPUNMAX+1));
6646 *c=(Unit)(carry-est*(DECDPUNMAX+1)); /* remainder */
6656 *c=(Unit)(carry-est*(DECDPUNMAX+1));
6664 *c=(Unit)(carry-est*(DECDPUNMAX+1)); /* remainder */
6671 *c=(Unit)(carry-est*(DECDPUNMAX+1));
6675 *c=(Unit)(carry-(DECDPUNMAX+1));
6681 *c=(Unit)(carry%(DECDPUNMAX+1));
6687 *c=(Unit)(carry%(DECDPUNMAX+1));
6696 *c=(Unit)carry; /* place as new unit */
6705 *c=(Unit)add;
6713 /* add an extra unit iff it would be non-zero */
6718 *c=(Unit)(add-carry-1);
6742 Unit *up; /* -> current Unit */
6758 cut=1; /* digit (1-DECDPUN) in Unit */
6759 up=dn->lsu; /* -> current Unit */
6777 if (cut>DECDPUN) { /* need new Unit */
6800 /* decReverse -- reverse a Unit array in place */
6803 /* uhi is the end of the array (highest Unit to include) */
6807 /* digit(s) in each unit are unaffected. */
6809 static void decReverse(Unit *ulo, Unit *uhi) {
6810 Unit temp;
6832 static Int decShiftToMost(Unit *uar, Int digits, Int shift) {
6833 Unit *target, *source, *first; /* work */
6838 if ((digits+shift)<=DECDPUN) { /* [fastpath] single-unit case */
6839 *uar=(Unit)(*uar*powers[shift]);
6847 if (cut==0) { /* unit-boundary case */
6853 /* split the source Unit and accumulate remainder for next */
6862 if (target<=first) *target=(Unit)next; /* write to target iff valid */
6863 next=rem*powers[DECDPUN-cut]; /* save remainder for next Unit */
6867 /* propagate any partial unit to one below and clear the rest */
6869 *target=(Unit)next;
6888 static Int decShiftToLeast(Unit *uar, Int units, Int shift) {
6889 Unit *target, *up; /* work */
6901 if (cut==DECDPUN) { /* unit-boundary case; easy */
6916 *target=(Unit)quot;
6928 *target=(Unit)(*target+rem*powers[DECDPUN-cut]);
6963 +(D2U(set->digits)-1)*sizeof(Unit));
7036 static void decSetCoeff(decNumber *dn, decContext *set, const Unit *lsu,
7039 uInt cut; /* cut point in Unit */
7040 const Unit *up; /* work */
7041 Unit *target; /* .. */
7087 /* the Unit with the first discarded digit. When reach it, extract */
7096 /* here up -> Unit with first discarded digit */
7098 if (cut==DECDPUN-1) { /* unit-boundary case (fast) */
7099 Unit half=(Unit)powers[DECDPUN]>>1;
7116 /* on unit boundary, so shift-down copy loop is simple */
7120 } /* unit-boundary case */
7125 if (cut==0) quot=*up; /* is at bottom of unit */
7126 else /* cut>0 */ { /* it's not at bottom of unit */
7150 /* here: up -> Unit of the array with bottom digit */
7151 /* cut is the division point for each Unit */
7152 /* quot holds the uncut high-order digits for the current unit */
7162 *target=(Unit)quot;
7174 *target=(Unit)(*target+rem*powers[DECDPUN-cut]);
7179 } /* not unit boundary */
7304 Unit *up; /* work */
7308 /* this is the last Unit (the msu) */
7311 *up=(Unit)powers[count-1]; /* here 999 -> 100 etc. */
7320 /* a full unit to check, with more to come */
7328 Unit *up, *sup; /* work */
7332 /* this is the last Unit (the msu) */
7336 *up=(Unit)powers[count]-1; /* here 100 in msu -> 999 */
7338 for (up=up-1; up>=dn->lsu; up--) *up=(Unit)powers[DECDPUN]-1;
7349 *sup=(Unit)powers[count-1]-1; /* here 999.. in msu -> 99.. */
7358 /* a full unit to check, with more to come */
7542 Unit *up; /* work */
7547 if (count>DECDPUN) *up=DECDPUNMAX; /* unit full o'nines */
7549 *up=(Unit)(powers[count]-1);
7691 const Unit *up; /* work */
7714 /* spin up whole units until reach the Unit with the unit digit */
7716 if (*up!=0) return BADINT; /* non-zero Unit to discard */
7743 /* collect any remaining unit(s) */
7779 Unit *msu; /* -> target cut point */
7855 const Unit *ul;
7856 Unit *ur, *uresp1;
7904 /* uar is the Unit array holding the number (this is often an */
7914 static Int decGetDigits(Unit *uar, Int len) {
7915 Unit *up=uar+(len-1); /* -> msu */
7926 if (*up==0) { /* unit is all 0s */
7928 digits-=DECDPUN; /* adjust for 0 unit */
7930 /* found the first (most significant) non-zero Unit */
7993 const Unit *up; /* work */
8039 /* decDumpAr -- display a unit array [debug/check aid] */
8044 static void decDumpAr(char name, const Unit *ar, Int len) {
8136 const Unit *up; /* work */
8198 printf("Bad Unit [%08lx] in %ld-digit number at offset %ld [maxuint %ld].\n",