From e80cf32fd5a51e01b158f71c7edbbeedaf4d74bf Mon Sep 17 00:00:00 2001 From: Gregor Schneider Date: Tue, 7 Jul 2009 16:19:34 +0000 Subject: [PATCH] Geoffroy Couprie : - Fix a printf case, where the exponent is zero - Implement exponent increment/decrement for printf in scientific notation My changes : - Change some lessequal/greaterequal to equal - Exchange OR with AND operation - Modify patch identation to match current code, remove FIXME - Skipped the ecvt part of the patch (not needed, sprint has the bugs) - Fixes five msvcrt printf winetests, see bug #4584 for more information svn path=/trunk/; revision=41799 --- reactos/lib/sdk/crt/stdio/lnx_sprintf.c | 35 ++++++++++++++++++------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/reactos/lib/sdk/crt/stdio/lnx_sprintf.c b/reactos/lib/sdk/crt/stdio/lnx_sprintf.c index 82465b24e9b..79daca4e7ea 100644 --- a/reactos/lib/sdk/crt/stdio/lnx_sprintf.c +++ b/reactos/lib/sdk/crt/stdio/lnx_sprintf.c @@ -168,7 +168,7 @@ numberf(char * buf, char * end, double num, char exp_sign, int size, int precisi int ro = 0; int isize; - double frac, intr; + double num2, frac, intr; double p; char c, sign, digits[66]; @@ -185,7 +185,12 @@ numberf(char * buf, char * end, double num, char exp_sign, int size, int precisi 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 (*n.__n == 0.0) + exponent = 0.0; + else + { + exponent = ie/3.321928; + } } if ( exp_sign == 'g' || exp_sign == 'G' ) @@ -201,17 +206,27 @@ numberf(char * buf, char * end, double num, char exp_sign, int size, int precisi if ( exp_sign == 'e' || exp_sign == 'E' ) { frac = modf(exponent,&e); - /* FIXME: this exponent over-/underflow scheme doesn't comply with the wanted behaviour - * needed at all or completely different in original? */ -#if 0 - if ( frac > 0.5 ) - e++; - else if ( frac < -0.5 ) + if (num < 0.0) e--; -#endif + if (frac >= 0.5) + e++; + else if (frac < -0.5) + e--; + + num2 = num/pow(10.0L,(long double)e); + if (num2 < 1.0 && num2 > -1.0) + { + e--; + num2 = num/pow(10.0L,(long double)e); + } + else if (num2 < -10.0 && num2 > 10.0) + { + e++; + num2 = num/pow(10.0L,(long double)e); + } /* size-5 because "e+abc" is going to follow */ - buf = numberf(buf, end, num/pow(10.0L,(long double)e), 'f', size-5, precision, type); + buf = numberf(buf, end, num2, 'f', size-5, precision, type); isize = 4; while(*(buf-1) == ' ') {