MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / decShiftToLeast

Function decShiftToLeast

extern/decNumber/decNumber.c:6739–6784  ·  view source on GitHub ↗

------------------------------------------------------------------ */ decShiftToLeast -- shift digits in array towards least significant */ / uar is the array */ units is length of the array, in units */ shift is the number of digits to remove from the lsu end; it */ must be zero or positive and <= than units*DECDPUN.

Source from the content-addressed store, hash-verified

6737/* the final result are unchanged. */
6738/* ------------------------------------------------------------------ */
6739static Int decShiftToLeast(Unit *uar, Int units, Int shift) {
6740 Unit *target, *up; // work
6741 Int cut, count; // work
6742 Int quot, rem; // for division
6743
6744 if (shift==0) return units; // [fastpath] nothing to do
6745 if (shift==units*DECDPUN) { // [fastpath] little to do
6746 *uar=0; // all digits cleared gives zero
6747 return 1; // leaves just the one
6748 }
6749
6750 target=uar; // both paths
6751 cut=MSUDIGITS(shift);
6752 if (cut==DECDPUN) { // unit-boundary case; easy
6753 up=uar+D2U(shift);
6754 for (; up<uar+units; target++, up++) *target=*up;
6755 return target-uar;
6756 }
6757
6758 // messier
6759 up=uar+D2U(shift-cut); // source; correct to whole Units
6760 count=units*DECDPUN-shift; // the maximum new length
6761 #if DECDPUN<=4
6762 quot=QUOT10(*up, cut);
6763 #else
6764 quot=*up/powers[cut];
6765 #endif
6766 for (; ; target++) {
6767 *target=(Unit)quot;
6768 count-=(DECDPUN-cut);
6769 if (count<=0) break;
6770 up++;
6771 quot=*up;
6772 #if DECDPUN<=4
6773 quot=QUOT10(quot, cut);
6774 rem=*up-quot*powers[cut];
6775 #else
6776 rem=quot%powers[cut];
6777 quot=quot/powers[cut];
6778 #endif
6779 *target=(Unit)(*target+rem*powers[DECDPUN-cut]);
6780 count-=cut;
6781 if (count<=0) break;
6782 }
6783 return target-uar+1;
6784 } // decShiftToLeast
6785
6786#if DECSUBSET
6787/* ------------------------------------------------------------------ */

Callers 2

decNumber.cFile · 0.85
decTrimFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected