[comp.sys.mac] Turbo Pascal bug.

larryh@tekgvs.TEK.COM (Larry Hutchinson) (12/05/87)

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.