From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111c93,7cfb7cf01916e84d,start X-Google-Attributes: gid111c93,public From: Stefan Illy Subject: Severe error with fscanf/sscanf (RH 4.2/5.0) Date: 1998/02/10 Message-ID: #1/1 X-Deja-AN: 323691037 Content-Transfer-Encoding: 8bit Sender: illy@itpgyro1.fzk.de Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 X-Complaints-To: usenet@nz12.rz.uni-karlsruhe.de X-Trace: nz12.rz.uni-karlsruhe.de 887100835 21749 (None) 141.52.61.15 Organization: Forschungszentrum Karlsruhe Newsgroups: comp.os.linux.alpha I encountered a serious problem on our two Linux-based Alphas: Both fscanf and sscanf produce errors when reading small floating point numbers (type double, exponent approx. -70) from files or strings. It happens only for a fraction of possible numbers (something in the range of 0.1 to 1 %, I don't know exactly). The following small C program should show this behaviour. On our systems it will produce the result `1.083877e-56' which differs from the input by 20 orders of magnitude! ------------------------------------------------------------------------ #include int main() { char str[256]; double x; sprintf(str, "5.9e-76"); sscanf(str, "%le", &x); fprintf(stdout, "%e\n", x); exit(0); } ------------------------------------------------------------------------ Adding one digit to the input (e.g. `5.91e-76'), will result in correct output. The behavior is compiler-independent, I was able to reproduce it with FORTRAN (both f2c/gcc-2.7.2.3 and g77/egcs-1.0.1) and the iostream operators of C++ (both gcc-2.7.2.3 and egcs-1.0.1). The hardware of both systems is identical (except of graphics card and peripheral devices): PC164 Motherboard 500 MHz 21164 Chip 256 MByte Memory The first system is running Redhat 4.2, Kernel updated to 2.0.32 (no additional patches), libc package: glibc-0.961212-7. The second system is running Redhat 5.0, Kernel updated to 2.0.32 (with alpha-patches-2.0.32-0.1.gz) libc package: glibc-2.0.5c-13. I am very interested, if someone could reproduce this behavior on PC164 and non-PC164 based systems. Where is the origin of this bug? libc, kernel, compilers? Best wishes, Stefan -- Stefan Illy | Institut fuer Technische Physik (ITP) | Forschungszentrum Karlsruhe GmbH | e-mail: stefan.illy@itp.fzk.de Hermann-von-Helmholtz-Platz 1 | phone: (+49) 07247/82-4165 D-76344 Eggenstein-Leopoldshafen, Germany | fax: (+49) 07247/82-2849