[Home]
[Contents]
[Chapter]
[Previous Algorithm]
[Next Algorithm]


Normalization of a multiple-precision number


normalize( a ) mp a; {int cy, i, la; la = length(a); start: cy = 0; for ( i=1; i<la; i++ ) { cy = (a[i] += cy) / BASE; a[i] -= cy*BASE; if (a[i]<0) {a[i] += BASE; cy--;} } while (cy>0) { a[i++] = cy%BASE; cy /= BASE;} if (cy<0) { a[la-1] += cy*BASE; for (i=1; i<la; i++) a[i] = -a[i]; storesign( a, sign(a)==POS ? NEG : POS ); goto start; } while (a[i-1]==0 && i>2) i--; storelength( a, i ); if ( i==2 && a[1]==0 ) storesign( a, POS ); };

C source (61.normal.c)



© Addison-Wesley Publishing Co. Inc.