Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!sdd.hp.com!spool.mu.edu!uwm.edu!rpi!uupsi!sunic!dkuug!diku!terra From: terra@diku.dk (Morten Welinder) Newsgroups: comp.lang.pascal Subject: Re: Is this not a bug? Message-ID: <1991Feb22.103032.489@odin.diku.dk> Date: 22 Feb 91 10:30:32 GMT References: <1991Feb20.170152.5401@ux1.cso.uiuc.edu> Sender: news@odin.diku.dk (Netnews System) Organization: Department of Computer Science, U of Copenhagen Lines: 43 mead@uxh.cso.uiuc.edu (Alan David Mead) writes: >I finally tracked down a problem with an application writen in >TP5.5: Since my values are all positive, I used words instead of >integers. The ABS() function, however, does not operate as (I) >expected with word parameters. This code demonstrates. While I >can imagine how the value is produced by ABS(), I think the manual's >description is deceptive. What does the net think? >============================================================ >program damnit; >const > Start : integer = 900; >var > w1,w2 : word; > i1, i2 : integer; > function Value:word; > begin > Start := Start - 200; > Value := Start; > end; >begin > w1 := Value; > w2 := Value; > writeln( 'ABS( ',w2,' - ',w1,' ) =? ',abs( w2 - w1 )); > i1 := Value; > i2 := Value; > writeln( 'ABS( ',i2,' - ',i1,' ) =? ',abs( i2 - i1 )); >end. >-- >Alan Mead : mead@uxh.cso.uiuc.edu (w1-w2) has type 'word' and so assumed positive; you force an overflow since w2