Article View: comp.sys.mac
Article #22567Turbo Pascal bug.
From: Larry Hutchinson
Date: Fri, 04 Dec 1987 21:56
Date: Fri, 04 Dec 1987 21:56
49 lines
1746 bytes
1746 bytes
I have discovered a bug in Turbo Pascal 1.0 involving an integer expression
screwing up a floating point comparison. As ususal this was burried deep
in a complicated math package and it took me half a day to find it.
I suppose it is possible that I am doing something wrong since I am not
a Pascal person -- if so, I apologize.
System 4.2, Finder 6.0, no Multi-finder.
In the following program, the first comparison is ok and the 2nd
is wrong. The wierd thing is that once this bug was worked around, the
rest of the program (a polynomial fit) appeared to work ok.
Larry Hutchinson, Tektronix, Inc. PO Box 500, MS 50-383, Beaverton, OR 97077
{ decvax,allegra }!tektronix!tekgvs!larryh
------------cut here----------------
PROGRAM test(input,output);
CONST
mz=0.0;
VAR
itmp: integer;
mj: real;
BEGIN
writeln('Demo of Turbo Pascal bug');
itmp := 30;
mj:= -10.0;
IF(mj>mz) THEN
writeln('first mj > comparison is wrong')
ELSE
writeln('first mj > comparison is ok');
itmp := 1+itmp; (* if this is reversed, to itmp+1, then is ok! *)
IF(mj>mz) THEN
writeln('2nd mj > comparison is wrong')
ELSE
writeln('2nd mj > comparison is ok');
readln;
END.
Technical Details
Message-ID:
<2929@tekgvs.TEK.COM>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!mit-eddie!uw-beaver!tektronix!tekcrl!tekgvs!larryhShow Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!mit-eddie!uw-beaver!tektronix!tekcrl!tekgvs!larryh From: larryh@tekgvs.TEK.COM (Larry Hutchinson) Newsgroups: comp.sys.mac Subject: Turbo Pascal bug. Message-ID: <2929@tekgvs.TEK.COM> Date: Fri, 4-Dec-87 16:56:57 EST Article-I.D.: tekgvs.2929 Posted: Fri Dec 4 16:56:57 1987 Date-Received: Thu, 10-Dec-87 21:17:05 EST Organization: Tektronix Inc., Beaverton, Or. Lines: 49 Keywords: Turbo Pascal bug programming