Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!dali.cs.montana.edu!uakari.primate.wisc.edu!sdd.hp.com!mips!apple!agate!usenet.ins.cwru.edu!eagle!roger.lerc.nasa.gov!togood From: togood@roger.lerc.nasa.gov (Chris Miller) Newsgroups: comp.lang.pascal Subject: Re: Is this a bug in TurboPascal Message-ID: <1991May1.121622.14722@eagle.lerc.nasa.gov> Date: 1 May 91 12:16:22 GMT References: <1991May1.021059.2129@ux1.cso.uiuc.edu> Sender: news@eagle.lerc.nasa.gov Organization: Nasa Lewis Research Center ( Cleveland ) Lines: 40 In article <1991May1.021059.2129@ux1.cso.uiuc.edu> husak@ux1.cso.uiuc.edu (BugsBunny) writes: >I'm running the following in TP and get the wrong answer.. Please correct >me if I'm wrong... > >program Is_this_wrong; >var > xx,yy,c1,c2,c3,c4: integer; >begin > xx := 639; yy := 479; > c1 := Trunc(50*xx/639); c2 := Trunc(50*yy/479); > c3 := Trunc(300*xx/639); c4 := Trunc(250*yy/479); > writeln(xx,yy,c1,c2,c3,c4); >end. > >OUTPUT: >639,479,50,50,-7,-23 > >How does it happen that the last two numbers are wrong and the rest right??? > Really confused in Illinois, > Steve No, it isn't wrong, you are creating a number that is too large for an integer variable (i.e. larger than MaxInt): program RollOver; var i: integer; l: longint; begin writeln('MaxInt =',MaxInt); for i := 50 to 52 do begin l := longint(i)*639; writeln(i, ' ',l,' ',i*639,' ',Trunc(i*639/639)); end; end. OUTPUT: MaxInt =32767 50 31950 31950 50 51 32589 32589 51 52 33228 -32308 -50