The following program: program bug(input,output); var x : real; begin x := 0.5000000000000E+00; writeln(' x = ',x:10:3); end. incorrectly prints out x = 5.000 It should print out x = 0.500 This program was compiled with GNU Pascal version 19990118, based on gcc-2.8.1, compiled Jun 15 1999 09:46:03. gpc --verbose Reading specs from /usr/lib/gcc-lib/i686-pc-linux-gnu/2.8.1/specs gpc version 19990118, based on gcc-2.8.1 ld -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/gcc-lib/i686-pc-linux-gnu/2.8.1/crtbegin.o -L/usr/lib/gcc-lib/i686-pc-linux-gnu/2.8.1 -lgpc -lm -lgcc -lc -lgcc /usr/lib/gcc-lib/i686-pc-linux-gnu/2.8.1/crtend.o /usr/lib/crtn.o /usr/lib/crt1.o(.text+0x36): undefined reference to `main' Rick Butler
Ricky W. Butler wrote:
[...] x := 0.5000000000000E+00; writeln(' x = ',x:10:3); [...]
incorrectly prints out
x = 5.000
[...]
Thanks for pointing us to this serious bug. I fixed it immediately but needed some time for testing. Here ist the patch to the GPC source file `gpc-lex.c' to fix the bug: 8< ------------------------------------------------------------- diff -r -U3 -p -N -X /usr/local/bin/gpcdiff.exclude gpc-old/p/gpc-lex.c gpc/p/gpc-lex.c --- gpc-old/p/gpc-lex.c Tue Jul 20 08:24:10 1999 +++ gpc/p/gpc-lex.c Tue Jul 20 12:02:34 1999 @@ -2044,7 +2044,6 @@ yylex () c = getc (finput); if ((c == '+') || (c == '-')) { - *p++ = c; if (c == '-') esign = -1; c = getc (finput); @@ -2053,11 +2052,15 @@ yylex () error ("real constant exponent has no digits"); while (isdigit (c)) { - expon = 10*expon+c-'0'; + expon = 10 * expon + c - '0'; c = getc (finput); } - expon = esign*expon+adjust_exp; - expon *= esign; + expon = esign * expon + adjust_exp; + if (expon < 0) + { + *p++ = '-'; + expon = - expon; + } exp_store_loc = p; store_exp (expon); p = exp_store_loc; 8< ------------------------------------------------------------- And here is the program I used to generate the program to test for further bugs of the same type. 8< ------------------------------------------------------------- Program GenRick; Const Tests = 10000; Var i, j, FieldWidth, digits: Integer; begin writeln ( 'Program Rick1a;' ); writeln; writeln ( 'Var' ); writeln ( ' x, y, a: Real;' ); writeln ( ' S: String ( 137 );' ); writeln ( ' i: Integer;' ); writeln ( ' OK: Boolean = true;' ); writeln; writeln ( 'begin' ); for i:= 1 to Tests do begin write ( ' x:= ' ); case Random ( 3 ) of 1: write ( '+' ); 2: write ( '-' ); end (* case *); for j:= 0 to Random ( 10 ) do write ( succ ( '0', Random ( 10 ) ) ); if Random ( 1 ) = 0 then begin write ( '.' ); for j:= 0 to Random ( 10 ) do write ( succ ( '0', Random ( 10 ) ) ); end (* if *); case Random ( 3 ) of 1: begin write ( 'e' ); case Random ( 3 ) of 1: write ( '+' ); 2: write ( '-' ); end (* case *); for j:= 0 to Random ( 2 ) do write ( succ ( '0', Random ( 10 ) ) ); end (* 1 *); 2: begin write ( 'E' ); case Random ( 3 ) of 1: write ( '+' ); 2: write ( '-' ); end (* case *); for j:= 0 to Random ( 2 ) do write ( succ ( '0', Random ( 10 ) ) ); end (* 2 *); end (* case *); writeln ( ';' ); case Random ( 7 ) of 0..3: begin FieldWidth:= Random ( 42 ); digits:= Random ( 13 ); writeln ( ' WriteStr ( S, x : ', FieldWidth, ' : ', digits, ' );' ); writeln ( ' a:= 5;' ); writeln ( ' for i:= 1 to ', digits, ' do' ); writeln ( ' a:= 0.1 * a;' ); end (* 0..3 *); 4, 5: begin FieldWidth:= Random ( 42 ); digits:= min ( 10, FieldWidth - 7 ); writeln ( ' WriteStr ( S, x : ', FieldWidth, ' );' ); writeln ( ' a:= abs ( x );' ); writeln ( ' for i:= 1 to ', digits, ' do' ); writeln ( ' a:= 0.1 * a;' ); end (* 4, 5 *); 6: begin writeln ( ' WriteStr ( S, x );' ); writeln ( ' a:= 1E-10 * abs ( x );' ); end (* 6 *); end (* case *); writeln ( ' ReadStr ( S, y );' ); writeln ( ' if abs ( x - y ) > a then' ); writeln ( ' begin' ); writeln ( ' OK:= false;' ); writeln ( ' writeln ( ''failed: '', x, '' '', y, '' '', abs ( x - y ), '' '', a, '' '', S );' ); writeln ( ' end (* if *);' ); end (* for *); writeln ( ' if OK then' ); writeln ( ' writeln ( ''OK'' )' ); writeln ( 'end.' ) end. 8< ------------------------------------------------------------- Hope this helps, Peter -- Peter Gerwinski, Essen, Germany, http://home.pages.de/~Peter.Gerwinski/ Maintainer GNU Pascal - http://home.pages.de/~GNU-Pascal/ - gpc-19990118 PGP key on request - 6C 94 45 BE 28 A4 96 - 0E CC E9 12 47 25 82 75 *** Vote against SPAM! ********* http://www.politik-digital.de/spam/ ***
Hi again, I wrote:
And here is the program I used to generate the program to test for further bugs of the same type.
Sorry - this program tests for the wrong thing. I am going to correct it Real Soon Now. In the meantime, be welcome to test the correctness of the bug fix by yourself. ;-) Peter -- Peter Gerwinski, Essen, Germany, http://home.pages.de/~Peter.Gerwinski/ Maintainer GNU Pascal - http://home.pages.de/~GNU-Pascal/ - gpc-19990118 PGP key on request - 6C 94 45 BE 28 A4 96 - 0E CC E9 12 47 25 82 75 *** Vote against SPAM! ********* http://www.politik-digital.de/spam/ ***
participants (2)
-
Peter Gerwinski -
Ricky W. Butler