synchronize differences between numberf, wnumberf, numberfl and wnumberfl, fixed bug in all 4 such that ("%6.1f", 42) was yielding " 42.0" instead of " 42.0" Modified: trunk/reactos/tools/ssprintf.cpp _____
Modified: trunk/reactos/tools/ssprintf.cpp --- trunk/reactos/tools/ssprintf.cpp 2006-01-09 11:24:09 UTC (rev 20750) +++ trunk/reactos/tools/ssprintf.cpp 2006-01-09 13:51:37 UTC (rev 20751) @@ -295,17 +295,13 @@
double e; long ie;
- //int x; - char *buf, *tmp; int i = 0; int j = 0; - //int k = 0; + int ro = 0;
double frac, intr; double p; - char sign; - char c; - char ro = 0; + char *buf, *tmp, sign, c; int result;
union @@ -316,12 +312,14 @@
n.__n = &__n;
- if ( exp_sign == 'g' || exp_sign == 'G' || exp_sign == 'e' || exp_sign == 'E' ) { + if ( exp_sign == 'g' || exp_sign == 'G' || exp_sign == 'e' || exp_sign == 'E' ) + { ie = ((unsigned int)n.n->exponent - (unsigned int)0x3ff); exponent = ie/3.321928; }
- if ( exp_sign == 'g' || exp_sign == 'G' ) { + if ( exp_sign == 'g' || exp_sign == 'G' ) + { type |= ZEROTRUNC; if ( exponent < -4 || fabs(exponent) >= precision ) exp_sign -= 2; // g -> e and G -> E @@ -329,7 +327,8 @@ exp_sign = 'f'; }
- if ( exp_sign == 'e' || exp_sign == 'E' ) { + if ( exp_sign == 'e' || exp_sign == 'E' ) + { frac = modf(exponent,&e); if ( frac > 0.5 ) e++; @@ -352,23 +351,29 @@ return true; }
- if ( exp_sign == 'f' ) { + if ( exp_sign == 'f' ) + { buf = (char*)alloca(4096); - if (type & LEFT) { + if (type & LEFT) type &= ~ZEROPAD; - }
c = (type & ZEROPAD) ? '0' : ' '; sign = 0; - if (type & SIGN) { - if (__n < 0) { + if (type & SIGN) + { + if (__n < 0) + { sign = '-'; __n = fabs(__n); size--; - } else if (type & PLUS) { + } + else if (type & PLUS) + { sign = '+'; size--; - } else if (type & SPACE) { + } + else if (type & SPACE) + { sign = ' '; size--; } @@ -377,11 +382,11 @@ frac = modf(__n,&intr);
// # flags forces a . and prevents trucation of trailing zero's - - if ( precision > 0 ) { - //frac = modfl(__n,&intr); + if ( precision > 0 ) + { i = precision-1; - while ( i >= 0 ) { + while ( i >= 0 ) + { frac*=10.0L; frac = modf(frac, &p); buf[i] = (int)p + '0'; @@ -391,23 +396,26 @@ size -= precision;
ro = 0; - if ( frac > 0.5 ) { + if ( frac > 0.5 ) ro = 1; - }
- if ( precision >= 1 || type & SPECIAL) { + if ( precision >= 1 || type & SPECIAL) + { buf[i++] = '.'; size--; } }
- if ( intr == 0.0 ) { + if ( intr == 0.0 ) + { buf[i++] = '0'; size--; } - else { - while ( intr > 0.0 ) { - p = intr; + else + { + while ( intr > 0.0 ) + { + p = intr; intr/=10.0L; modf(intr, &intr);
@@ -419,12 +427,15 @@ }
j = 0; - while ( j < i && ro == 1) { - if ( buf[j] >= '0' && buf[j] <= '8' ) { + while ( j < i && ro == 1) + { + if ( buf[j] >= '0' && buf[j] <= '8' ) + { buf[j]++; ro = 0; } - else if ( buf[j] == '9' ) { + else if ( buf[j] == '9' ) + { buf[j] = '0'; } j++; @@ -434,7 +445,6 @@
buf[i] = 0;
- size -= precision; if (!(type&(ZEROPAD+LEFT))) { while(size-->0) @@ -446,18 +456,16 @@ }
if (!(type&(ZEROPAD+LEFT))) + { while(size-->0) - { f += ' '; - } - if (type & SPECIAL) { }
if (!(type & LEFT)) + { while (size-- > 0) - { f += c; - } + }
tmp = buf; if ( type & ZEROTRUNC && ((type & SPECIAL) != SPECIAL) ) @@ -469,9 +477,6 @@ i--; } } -// else -// while (i < precision--) -// putc('0', f); while (i-- > 0) { f += tmp[i]; @@ -493,10 +498,11 @@
int i = 0; int j = 0; + int ro = 0;
double frac, intr; double p; - wchar_t *buf, *tmp, sign, c, ro = 0; + wchar_t *buf, *tmp, sign, c; int result;
union @@ -507,7 +513,8 @@
n.__n = &__n;
- if ( exp_sign == L'g' || exp_sign == L'G' || exp_sign == L'e' || exp_sign == L'E' ) { + if ( exp_sign == L'g' || exp_sign == L'G' || exp_sign == L'e' || exp_sign == L'E' ) + { ie = ((unsigned int)n.n->exponent - (unsigned int)0x3ff); exponent = ie/3.321928; } @@ -576,11 +583,11 @@ frac = modf(__n,&intr);
// # flags forces a . and prevents trucation of trailing zero's - - if ( precision > 0 ) { - //frac = modfl(__n,&intr); + if ( precision > 0 ) + { i = precision-1; - while ( i >= 0 ) { + while ( i >= 0 ) + { frac*=10.0L; frac = modf(frac, &p); buf[i] = (int)p + L'0'; @@ -590,22 +597,25 @@ size -= precision;
ro = 0; - if ( frac > 0.5 ) { + if ( frac > 0.5 ) ro = 1; - }
- if ( precision >= 1 || type & SPECIAL) { + if ( precision >= 1 || type & SPECIAL) + { buf[i++] = L'.'; size--; } }
- if ( intr == 0.0 ) { + if ( intr == 0.0 ) + { buf[i++] = L'0'; size--; } - else { - while ( intr > 0.0 ) { + else + { + while ( intr > 0.0 ) + { p = intr; intr/=10.0L; modf(intr, &intr); @@ -618,12 +628,15 @@ }
j = 0; - while ( j < i && ro == 1) { - if ( buf[j] >= L'0' && buf[j] <= L'8' ) { + while ( j < i && ro == 1) + { + if ( buf[j] >= L'0' && buf[j] <= L'8' ) + { buf[j]++; ro = 0; } - else if ( buf[j] == L'9' ) { + else if ( buf[j] == L'9' ) + { buf[j] = L'0'; } j++; @@ -633,7 +646,6 @@
buf[i] = 0;
- size -= precision; if (!(type&(ZEROPAD+LEFT))) { while(size-->0) @@ -645,18 +657,16 @@ }
if (!(type&(ZEROPAD+LEFT))) + { while(size-->0) - { f += L' '; - } - if (type & SPECIAL) { }
if (!(type & LEFT)) + { while (size-- > 0) - { f += c; - } + }
tmp = buf; if ( type & ZEROTRUNC && ((type & SPECIAL) != SPECIAL) ) @@ -687,34 +697,31 @@ long double e; long ie;
- //int x; - char *buf, *tmp; int i = 0; int j = 0; - //int k = 0; + int ro = 0;
long double frac, intr; long double p; - char sign; - char c; - char ro = 0; - + char *buf, *tmp, sign, c; int result;
union { - long double* __n; - ieee_long_double_t* n; + long double* __n; + ieee_long_double_t* n; } n;
n.__n = &__n;
- if ( exp_sign == 'g' || exp_sign == 'G' || exp_sign == 'e' || exp_sign == 'E' ) { + if ( exp_sign == 'g' || exp_sign == 'G' || exp_sign == 'e' || exp_sign == 'E' ) + { ie = ((unsigned int)n.n->exponent - (unsigned int)0x3fff); exponent = ie/3.321928; }
- if ( exp_sign == 'g' || exp_sign == 'G' ) { + if ( exp_sign == 'g' || exp_sign == 'G' ) + { type |= ZEROTRUNC; if ( exponent < -4 || fabs(exponent) >= precision ) exp_sign -= 2; // g -> e and G -> E @@ -722,11 +729,12 @@ exp_sign = 'f'; }
- if ( exp_sign == 'e' || exp_sign == 'E' ) { + if ( exp_sign == 'e' || exp_sign == 'E' ) + { frac = modfl(exponent,&e); if ( frac > 0.5 ) e++; - else if ( frac < -0.5 ) + else if ( frac < -0.5 ) e--;
result = numberf(f,__n/powl(10.0L,e),'f',size-4, precision, type); @@ -747,12 +755,9 @@
if ( exp_sign == 'f' ) { - buf = (char*)alloca(4096); if (type & LEFT) - { type &= ~ZEROPAD; - }
c = (type & ZEROPAD) ? '0' : ' '; sign = 0; @@ -763,11 +768,13 @@ sign = '-'; __n = fabs(__n); size--; - } else if (type & PLUS) + } + else if (type & PLUS) { sign = '+'; size--; - } else if (type & SPACE) + } + else if (type & SPACE) { sign = ' '; size--; @@ -779,8 +786,6 @@ // # flags forces a . and prevents trucation of trailing zero's if ( precision > 0 ) { - //frac = modfl(__n,&intr); - i = precision-1; while ( i >= 0 ) { @@ -794,9 +799,7 @@
ro = 0; if ( frac > 0.5 ) - { ro = 1; - }
if ( precision >= 1 || type & SPECIAL) { @@ -814,7 +817,7 @@ { while ( intr > 0.0 ) { - p=intr; + p = intr; intr/=10.0L; modfl(intr, &intr);
@@ -826,7 +829,8 @@ }
j = 0; - while ( j < i && ro == 1) { + while ( j < i && ro == 1) + { if ( buf[j] >= '0' && buf[j] <= '8' ) { buf[j]++; @@ -843,7 +847,6 @@
buf[i] = 0;
- size -= precision; if (!(type&(ZEROPAD+LEFT))) { while(size-->0) @@ -859,14 +862,13 @@ while(size-->0) f += ' '; } - if (type & SPECIAL) { - }
if (!(type & LEFT)) + { while (size-- > 0) - { f += c; - } + } + tmp = buf; if ( type & ZEROTRUNC && ((type & SPECIAL) != SPECIAL) ) { @@ -896,29 +898,31 @@ long double e; long ie;
- wchar_t *buf, *tmp, sign, c, ro = 0; int i = 0; int j = 0; + int ro = 0;
long double frac, intr; long double p; - + wchar_t *buf, *tmp, sign, c; int result;
union { - long double* __n; - ieee_long_double_t* n; + long double* __n; + ieee_long_double_t* n; } n;
n.__n = &__n;
- if ( exp_sign == L'g' || exp_sign == L'G' || exp_sign == L'e' || exp_sign == L'E' ) { + if ( exp_sign == L'g' || exp_sign == L'G' || exp_sign == L'e' || exp_sign == L'E' ) + { ie = ((unsigned int)n.n->exponent - (unsigned int)0x3fff); exponent = ie/3.321928; }
- if ( exp_sign == L'g' || exp_sign == L'G' ) { + if ( exp_sign == L'g' || exp_sign == L'G' ) + { type |= ZEROTRUNC; if ( exponent < -4 || fabs(exponent) >= precision ) exp_sign -= 2; // g -> e and G -> E @@ -926,11 +930,12 @@ exp_sign = 'f'; }
- if ( exp_sign == L'e' || exp_sign == L'E' ) { + if ( exp_sign == L'e' || exp_sign == L'E' ) + { frac = modfl(exponent,&e); if ( frac > 0.5 ) e++; - else if ( frac < -0.5 ) + else if ( frac < -0.5 ) e--;
result = wnumberf(f,__n/powl(10.0L,e),L'f',size-4, precision, type); @@ -951,12 +956,9 @@
if ( exp_sign == L'f' ) { - buf = (wchar_t*)alloca(4096*sizeof(wchar_t)); if (type & LEFT) - { type &= ~ZEROPAD; - }
c = (type & ZEROPAD) ? L'0' : L' '; sign = 0; @@ -967,11 +969,13 @@ sign = L'-'; __n = fabs(__n); size--; - } else if (type & PLUS) + } + else if (type & PLUS) { sign = L'+'; size--; - } else if (type & SPACE) + } + else if (type & SPACE) { sign = L' '; size--; @@ -983,8 +987,6 @@ // # flags forces a . and prevents trucation of trailing zero's if ( precision > 0 ) { - //frac = modfl(__n,&intr); - i = precision-1; while ( i >= 0 ) { @@ -998,9 +1000,7 @@
ro = 0; if ( frac > 0.5 ) - { ro = 1; - }
if ( precision >= 1 || type & SPECIAL) { @@ -1018,7 +1018,7 @@ { while ( intr > 0.0 ) { - p=intr; + p = intr; intr/=10.0L; modfl(intr, &intr);
@@ -1030,7 +1030,8 @@ }
j = 0; - while ( j < i && ro == 1) { + while ( j < i && ro == 1) + { if ( buf[j] >= L'0' && buf[j] <= L'8' ) { buf[j]++; @@ -1047,7 +1048,6 @@
buf[i] = 0;
- size -= precision; if (!(type&(ZEROPAD+LEFT))) { while(size-->0) @@ -1063,14 +1063,13 @@ while(size-->0) f += L' '; } - if (type & SPECIAL) { - }
if (!(type & LEFT)) + { while (size-- > 0) - { f += c; - } + } + tmp = buf; if ( type & ZEROTRUNC && ((type & SPECIAL) != SPECIAL) ) {