Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!hp4nl!eurtrx!euraiv1!reino From: reino@cs.eur.nl (Reino de Boer) Newsgroups: comp.lang.pascal Subject: Re: Is this not a bug? Message-ID: <1991Feb22.111536.13080@cs.eur.nl> Date: 22 Feb 91 11:15:36 GMT References: <1991Feb20.170152.5401@ux1.cso.uiuc.edu> <5777@husc6.harvard.edu> Reply-To: reino@cs.eur.nl Organization: Erasmus University Rotterdam Lines: 53 In <5777@husc6.harvard.edu> rind@popvax.uucp (747707@d.rind) writes: >I don't see this as a bug. It's not ABS that's not functioning as you >expect. Any other function would have behaved the same way. When >you took the difference of two WORD variables inside a function call, >the result was a WORD. Since a WORD is unsigned, it could never >go negative, and so the difference had to be a number between >0 and 65535. The function call ABS(w2-w1) is equivalent to creating >a third word variable w3 and doing w3 := w2-w1 followed by ABS(w3). >I can't see the point in ever taking the absolute value of a WORD >type variable, but perhaps someone else has some thoughts on this. You are ABSolutely right, but when the original poster really wants the equivalent of if w1 > w2 then (hope you see the point) w3 := w1 - w2 else w3 := w2 - w1 to get the absolute difference between two words, the following code seems to work: w3 := word(abs(integer(w1 - w2))) but, as anyone who understands the problem knows, this fails for any values of w1 and w2 with: w1 < w2 and w2 - w1 > 32768 since that large a difference cannot be represented as an abs(integer(i)) So, your best bet would be to write something like function abs_diff( w1, w2 : word ) : word; begin if w1 > w2 then abs_diff := w1 - w2 else abs_diff := w2 - w1 end; Hope this helps -- Reino >David Rind >rind@popvax.harvard.edu -- Reino R. A. de Boer "We want to build the right product right, right?" Erasmus University Rotterdam ( Informatica ) e-mail: reino@cs.eur.nl