Index: lib/sdk/crt/stdio/lnx_sprintf.c =================================================================== --- lib/sdk/crt/stdio/lnx_sprintf.c (revision 41280) +++ lib/sdk/crt/stdio/lnx_sprintf.c (working copy) @@ -168,7 +168,7 @@ int ro = 0; int isize; - double frac, intr; + double num2, frac, intr; double p; char c, sign, digits[66]; @@ -184,8 +184,13 @@ 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 + { + ie = ((unsigned int)n.n->exponent - (unsigned int)0x3ff); + exponent = ie/3.321928; + } } if ( exp_sign == 'g' || exp_sign == 'G' ) @@ -203,15 +208,27 @@ 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 ) + if(num<0.0) + e--; + if ( frac >= 0.5) e++; - else if ( frac < -0.5 ) + else if (frac <= -0.5) e--; -#endif + 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) == ' ') { Index: lib/sdk/crt/stdlib/ecvtbuf.c =================================================================== --- lib/sdk/crt/stdlib/ecvtbuf.c (revision 41280) +++ lib/sdk/crt/stdlib/ecvtbuf.c (working copy) @@ -56,6 +56,9 @@ else *sign = 0; + if (ndigits<0) + ndigits = 0; + /* Special values get special treatment. */ if (strncmp (s, "Inf", 3) == 0) { @@ -74,6 +77,12 @@ while (*s && *s != decimal && d - buf < ndigits) *d++ = *s++; + /*From http://www.opengroup.org/onlinepubs/009695399/functions/gcvt.html: + the high order digit = 0. Returning 0 or 1 for decpt is unspecified. + Here we comply with the winetest for printf*/ + if(value == 0) + *decpt = 0; + else /* If we don't see any exponent, here's our decimal point. */ *decpt = d - buf; if (*s)