Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!SUN.COM!wmb From: wmb@SUN.COM (Mitch Bradley) Newsgroups: comp.lang.forth Subject: Re: Standard follies Message-ID: <8907181620.AA07088@jade.berkeley.edu> Date: 18 Jul 89 13:43:03 GMT Sender: daemon@ucbvax.BERKELEY.EDU Reply-To: Forth Interest Group International List Organization: The Internet Lines: 45 Many thanks to Rainer Woitok for reminding me that: > on a 1's complement machine, negative zero is FFFF > (16 bit words assumed). 8000 is the smallest ("most negative") number Sorry for the error; what I said was correct for sign/magnitude representation rather than one's complement. In any case, the principle still holds; "0=" returns true for two distinct bit patterns, one of which contains nonzero bits. Worse yet, the standard defines "true" (i.e. that number which is returned by comparison operators) as "-1" (it used to be "1" in Forth 79) so that all the bits will be set (which is not correct for one's complement, where "-1" is hex fffe). The reason for having all the bits set was supposed to be to allow flags to participate in AND and OR expressions with less chance for error. For example, suppose I have the following code: ( value ) 40 and num1 num2 < and if This code would work in Forth-83 but not in Forth-79. The intention is obviously to test whether the 40 bit in value is set and num1 is less than num2. In Forth-79, < returns 1 , but AND'ing 40 with 1 gives 0. In Forth-83, < returns -1 (= ffff on 2's complement machines), so you can AND a flag with any non-false value and still get non-false. This code happens to work on one's complement machines too, but it wouldn't work of you were masking with 1 instead of 40. ( "1 -1" and is 0 in 1's-complement) The point is, if you want to write portable code, make sure that you follow bit-masking operations with a test for nonzero, to turn the bit mask into a real, honest-to-goodness, true flag. But wait! There is no operator to test for nonzero! The closest is 0= 0= , and as we've seen, that doesn't work on one's-complement machines. The bottom line here is that Forth has a problem. Other languages have bitten the bullet and have distinguished between boolean operators and bitwise logical operators (C: && vs & Fortran: .AND. vs AND() ). Forth uses the same operator for different purposes, just because it happen to work on most machines in most cases. Mitch (give me precise operators!) Bradley