Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!iuvax!maytag!watstat!dmurdoch From: dmurdoch@watstat.waterloo.edu (Duncan Murdoch) Newsgroups: comp.lang.pascal Subject: Re: HELP with Turbo Pascal problem Keywords: Turbo Pascal Message-ID: <1092@maytag.waterloo.edu> Date: 6 Jan 90 05:34:41 GMT References: <3433@tahoe.unr.edu> Sender: daemon@maytag.waterloo.edu Reply-To: dmurdoch@watstat.waterloo.edu (Duncan Murdoch) Organization: U. of Waterloo, Ontario Lines: 23 In article <3433@tahoe.unr.edu> rfh@unssun.nevada.edu (J.A. MacDonald) writes: >HELP!! > > I wrote the following program in TurboPascal 5.5 and got a very >wrong answer. One would expect to get an output value for j of 64516, >but instead get -1020. ... > i : integer; > j : real; > >begin > i := 254; > j := i * i; You got what you're supposed to get, according to the specs for TP. It evaluates ordinal expressions in the smallest type that will hold the operands; thus i * i is evaluated as an integer, and it overflows before it gets converted to real and stored in j. You can get the result you expect by using j := i * longint(i); or something similar, to force the calculation to take place as a longint. Duncan Murdoch