X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f X-Recipient: djgpp-workers AT delorie DOT com Message-ID: <52CB29B1.3010904@gmx.de> Date: Mon, 06 Jan 2014 23:09:53 +0100 From: Juan Manuel Guerrero User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: djgpp-workers AT delorie DOT com Subject: _doprnt bug fix if mantissa fraction precision exceeds the default of 39 decimal digits. Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:3RbRuydr3n4uAJlwmV1qGk4wAopyIPwptVs5H5pjmIX6p0MZhQw XVhaOXaYUKM8HhQ43w49k4BQN+9y6mDUjcbOfVREBoio1nsG/yYVn7Jykh/q7pVthreVbQz sarTzP/0ANwo6z9Px5yXdNEoHCHQsQ44w9QbXY0shaZq2Rd4Tl6I/I4wdipRvHen9RdWgKg 9NS/GfEvdvdh7XPFrf6CA== Reply-To: djgpp-workers AT delorie DOT com Please look at the following code snippet: #include int main(void) { printf("%.60Le\n", 1.75L); return 0; } It must produce the following output (linux): 1.750000000000000000000000000000000000000000000000000000000000e+00 but it produces the following output: 1.750000000000000000000000000000000000000e+00000000000000000000000 _doprnt limits the precision to 39 decimal digits. If a larger precision has been specified then zeros are added to the end of the conversion string instead to the end of the fraction part coded in the conversion string. The code above is from a test case of libunistring-0.9.3.tar.gz that fails for DJGPP 2.03 and 2.04. This bug appears only if the specified precision really exceeds 39 [hex]decimal digits. Precision larger than 39 digits are seldom. The patch below will fix the issue. As usual suggestions, objections, comments are welcome. Regards, Juan M. Guerrero 2014-01-06 Juan Manuel Guerrero * djgpp/src/libc/ansi/stdio/doprnt.c: Handle case when mantissa fraction precision exceeds max default precision of 39 decimal digits. diff -aprNU5 djgpp.orig/src/libc/ansi/stdio/doprnt.c djgpp/src/libc/ansi/stdio/doprnt.c --- djgpp.orig/src/libc/ansi/stdio/doprnt.c 2014-01-06 18:54:44 +0000 +++ djgpp/src/libc/ansi/stdio/doprnt.c 2014-01-06 22:44:06 +0000 @@ -1,5 +1,6 @@ +/* Copyright (C) 2014 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 2012 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 2011 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 2008 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */ @@ -404,12 +405,13 @@ rflag: * cvt may have to round up past the "start" of the * buffer, i.e. ``intf("%.2f", (double)9.999);''; * if the first char isn't NUL, it did. */ *buf = '\0'; - size = doprnt_cvtl(_ldouble, prec, flags, &softsign, *fmt, buf, + size = doprnt_cvtl(_ldouble, prec + fpprec, flags, &softsign, *fmt, buf, buf + sizeof(buf)); + fpprec = 0; /* Floating point fraction precision greater than 39 digits already adjusted in doprnt_cvtl. */ /* * If the format specifier requested an explicit sign, * we print a negative sign even if no significant digits * will be shown, and we also print a sign for a NaN. In * other words, "%+f" might print -0.000000, +NaN and -NaN.