This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libfortran/24685] real(16) formatted input is broken for huge values
- From: "sje at cup dot hp dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 15 Mar 2006 16:44:52 -0000
- Subject: [Bug libfortran/24685] real(16) formatted input is broken for huge values
- References: <bug-24685-8500@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #12 from sje at cup dot hp dot com 2006-03-15 16:44 -------
At least on IA64, I don't think there is a way to make this test work. I tried
a change similar to yours. I also changed the setting of ndigits (uses the
magic number 27 in a couple of places), changed the number 31 in the sprintf
statement and the number 32 (buffer size) in the snprintf statement. This
fixed the LDBL_MAX problem but the test still failed on the LDBL_MIN part of
the test.
The attached C program fails on IA64 because the printf rounds the last digit
of MIN_LDBL down when it prints it and so it can't be read back in. The basic
problem is that LDBL_MAX and LDBL_MIN (or for that matter DBL_MIN and DBL_MAX)
cannot be represented exactly in decimal form so printf has to do some rounding
that may make the process non-reversable when trying to go back via strtod or
strtold. I looked to see if there was a float or double version of this test
and I didn't find one, if there was one I think it would fail on some platforms
because the write/read sequence is not gauranteed to return the original value
due to possible rounding during the writing and/or reading process.
#include <stdio.h>
#include <float.h>
#include <errno.h>
main()
{
char buffer[64];
long double x = LDBL_MIN;
sprintf(buffer, "%63.40Le", x);
printf("==%s==\n", buffer);
errno = 0;
x = strtold(buffer, 0);
printf("errno = %d\n", errno);
}
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24685