HP3000-L Archives

February 1995, Week 2

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
"Tony B. Shepherd" <[log in to unmask]>
Reply To:
Tony B. Shepherd
Date:
Wed, 8 Feb 1995 16:24:26 -0500
Content-Type:
text/plain
Parts/Attachments:
text/plain (43 lines)
In article <[log in to unmask]>,
[log in to unmask] (Bruce Toback) wrote:
>Tony Shepherd writes:
>>To illustrate, a one byte binary field has a range of -128 .. +127 (a total
>>of 256 different values).  x'80' represents -128 in this case.
>
>>IMHO it would not be wise to count on this implementation quirk in production
>>systems - if I remember correctly, the Basic interpreter uses this value to
>>detect references to uninitialized variables.
>
>It is in fact safe to count on this characteristic. It's the BASIC
>interpreter with the "implementation quirk" that uses a legal value
>to represent an uninitialized variable. The property that Tony notes,
>that a binary value consisting of a high-order 1 bit followed by
>all zero bits is the value -2^n rather than -0, is a property
>of the 2's-complement integer representation used in almost all
>modern computers.
  [ clip ]
> In short, it's safe to rely on binary 10...0 as a large negative
> integer in any commercially-available computer.
 
I'm sorry - that didn't come out very clearly, did it?  The 'implementation
quirk' I was referring to is the hardware: there is one exception in the
range of numbers to the rule -( -( A ) ) <> A.  In other words, -( -( -128) )
will fail because -( +128) cannot be represented.  Other problems come up
such as COMPLEMENT(COMPLEMENT(X)) <> X and so forth.  I have heard some call
this a 'corner case' - I presume it means the algorithm breaks down at the
(extreme) limits of the range.
 
So I agree - it is a large (the largest possible) negative integer - but it
is certainly not negative zero.
 
The Basic interpreter does not have a quirk - it uses the maximum negative
value to trap references to variables not yet initialized by the program.
 
If you choose to use such a value directly (as opposed to a switch saying the
variable is as yet undefined), you may want to localize and document it as
much as possible - so your new maintenance programmer doesn't "fix" it for
you (if zero + one = one, why doesn't negative zero + one = one?).
 
--
Tony B. Shepherd  --  [log in to unmask]

ATOM RSS1 RSS2