* Severe errors with fscanf/sscanf (RH 4.2/5.0)
@ 1998-02-10 8:38 Stefan Illy
0 siblings, 0 replies; 7+ messages in thread
From: Stefan Illy @ 1998-02-10 8:38 UTC (permalink / raw)
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 <stdio.h>
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
--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject. Do not send it to axp-list@redhat.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Severe errors with fscanf/sscanf (RH 4.2/5.0)
@ 1998-02-10 13:31 Uncle George
0 siblings, 0 replies; 7+ messages in thread
From: Uncle George @ 1998-02-10 13:31 UTC (permalink / raw)
yup, get right answer on i386/redhat 4.2
get wrong ans on alpha/redhat 4.2
gat
oops
Stefan Illy wrote:
> 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).
>
--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject. Do not send it to axp-list@redhat.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Severe errors with fscanf/sscanf (RH 4.2/5.0)
@ 1998-02-10 19:22 Richard Henderson
0 siblings, 0 replies; 7+ messages in thread
From: Richard Henderson @ 1998-02-10 19:22 UTC (permalink / raw)
On Tue, Feb 10, 1998 at 09:38:55AM +0100, Stefan Illy wrote:
> 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).
Nasty.
There is a program called glibcbug that will submit an official
bug report on glibc, which will help prevent such problems from
getting lost or forgotten.
r~
--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject. Do not send it to axp-list@redhat.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Severe errors with fscanf/sscanf (RH 4.2/5.0)
@ 1998-02-11 17:46 Uncle George
0 siblings, 0 replies; 7+ messages in thread
From: Uncle George @ 1998-02-11 17:46 UTC (permalink / raw)
it seems that one cannot shift more that 63 bits with a right shift on the
alpha. Anyone trying to shift 64 or more bits will result in a no-op,
rather than clearing out the whole register. The contents of that register
appears to be untouched.
This is a problem for programs like lshift.s (
libc.works/sysdeps/alpha/lshift.s ) or the more generic lshift.c (
libc.works/sysdeps/generic/lshift.c ), which when a shift count ( cnt ) of
zero, tries first to do a left shift of 0 bits, but then also a right
shift of 64-0 bits ( a no-op on the alpha, other machines would have
shifted out all the bits in the register ). This hardware feature in
essence trashes the premise behind the lshift subroutine.
in the example of stephan illy, the mantissa get fully filled up , and
strtod_internal() deceides to shift 0 bits. needless to say the mantissa
gets messed up.
FIX:
i dunno, do all the >> and << have to be checked in GLIB et al, to see if
a zero is wanted out of the shift operation? ouch!
Uncle George wrote:
> yup,
> Stefan Illy wrote:
>
> > 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).
--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject. Do not send it to axp-list@redhat.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Severe errors with fscanf/sscanf (RH 4.2/5.0)
[not found] <34E1E403.8E292D6E@voicenet.com>
@ 1998-02-11 19:26 ` Richard Henderson
0 siblings, 0 replies; 7+ messages in thread
From: Richard Henderson @ 1998-02-11 19:26 UTC (permalink / raw)
--t9RHnE3ZwKMSgU+y
Content-Type: text/plain; charset=us-ascii
On Wed, Feb 11, 1998 at 12:46:44PM -0500, Uncle George wrote:
> it seems that one cannot shift more that 63 bits with a right shift on the
> alpha. Anyone trying to shift 64 or more bits will result in a no-op,
That is correct. In the definition of mpn_lshift, COUNT must be
between 1 and N-1, so it was the caller that was in error. Here
is a patch, which fixes the example that was provided.
Thanks for the pointer.
r~
--t9RHnE3ZwKMSgU+y
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=d-fp
1998-02-11 19:16 Richard Henderson <rth@cygnus.com>
* stdlib/strtod.c (STRTOF): Don't call lshift with zero count.
Index: stdlib/strtod.c
===================================================================
RCS file: /egcs/carton/cvsfiles/libc/stdlib/strtod.c,v
retrieving revision 1.36.2.3
diff -u -p -r1.36.2.3 strtod.c
--- strtod.c 1997/11/19 23:26:56 1.36.2.3
+++ strtod.c 1998/02/11 19:16:12
@@ -874,10 +874,13 @@ INTERNAL (STRTOF) (nptr, endptr, group)
count_leading_zeros (cnt, den[densize - 1]);
- (void) __mpn_lshift (den, den, densize, cnt);
- cy = __mpn_lshift (num, num, numsize, cnt);
- if (cy != 0)
- num[numsize++] = cy;
+ if (cnt > 0)
+ {
+ (void) __mpn_lshift (den, den, densize, cnt);
+ cy = __mpn_lshift (num, num, numsize, cnt);
+ if (cy != 0)
+ num[numsize++] = cy;
+ }
/* Now we are ready for the division. But it is not necessary to
do a full multi-precision division because we only need a small
--t9RHnE3ZwKMSgU+y--
--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject. Do not send it to axp-list@redhat.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Severe errors with fscanf/sscanf (RH 4.2/5.0)
@ 1998-02-11 23:33 Uncle George
0 siblings, 0 replies; 7+ messages in thread
From: Uncle George @ 1998-02-11 23:33 UTC (permalink / raw)
the definition is posted where ?
what of all the other lshift/rshift that may have a shift count of >64 passed to
it?
Richard Henderson wrote:
> That is correct. In the definition of mpn_lshift, COUNT must be
> between 1 and N-1, so it was the caller that was in error. Here
> is a patch, which fixes the example that was provided.
>
> Thanks for the pointer.
>
> r~
>
> ------------------------------------------------------------------------
>
> d-fp Name: d-fp
> Type: Plain Text (text/plain)
--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject. Do not send it to axp-list@redhat.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Severe errors with fscanf/sscanf (RH 4.2/5.0)
[not found] <34E23533.2929FAC3@voicenet.com>
@ 1998-02-11 23:52 ` Richard Henderson
0 siblings, 0 replies; 7+ messages in thread
From: Richard Henderson @ 1998-02-11 23:52 UTC (permalink / raw)
On Wed, Feb 11, 1998 at 06:33:08PM -0500, Uncle George wrote:
> the definition is posted where ?
The gmp package from which these routines were taken have
good documentation.
> what of all the other lshift/rshift that may have a shift count of >64
> passed to it?
The majority of the calls are already handled correctly. That's
not to say that there are no other missed cases, but it is not a
widespread problem.
r~
--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject. Do not send it to axp-list@redhat.com
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~1998-02-11 23:52 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <34E23533.2929FAC3@voicenet.com>
1998-02-11 23:52 ` Severe errors with fscanf/sscanf (RH 4.2/5.0) Richard Henderson
1998-02-11 23:33 Uncle George
[not found] <34E1E403.8E292D6E@voicenet.com>
1998-02-11 19:26 ` Richard Henderson
-- strict thread matches above, loose matches on Subject: below --
1998-02-11 17:46 Uncle George
1998-02-10 19:22 Richard Henderson
1998-02-10 13:31 Uncle George
1998-02-10 8:38 Stefan Illy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox