[comp.lang.modula2] -32768

agnew@trwrc.UUCP (Robert A. Agnew) (04/25/89)

	My comments about -32768 have prompted some rather strange replies.
Please accept my appologies for the hastily posted, poorly phrased,
and not well thought-out posting. Let me replace it with the following 
summary of my thoughts and the replies which I received. 

	There appear to be only two logically consistent alternatives.

1)   Complete the modulo 32768 paridgm by disallowing the value -32768. 
     This would require checking for the value 8000H after every operation
	 and considering it as an overflow condition.

2)   Allow the value 8000H to represent -32768. This would require the
	 ability to discriminate between the two cases:

		 n := -32767 -1;    (* legal -- no overflow *)

	and

		 n := 32767 - 1; n := -n; (* illegal -- produces overflow *)

It appears at first glance that 2) is more trouble to implement than
it's worth. Unless someone can reccommend an efficient and iron-clad
algorithm for 2), I suggest we adopt 1). This was my original recomend-
ation. My original complaint was that the hardware allows -32768
rather than considering it as an overflow. I also was implying that
the original hardware scheme was inconsistent in that respect, but
when I built my first two's-compliment accumulator out of DTL in
1967, the inconsistency wasn't apparent to me either.

Pat.Terry@p101.f19.n490.z2.fidonet.org (Pat Terry) (04/29/89)

There has been considerable discussion here recently about
      I := -32768;
      WriteInt(I,10)

This is handled "correctly" by JPI, QuickMod and FTL compilers.

FST objects to I := -32768.

I put the point to Roger Carvalho, the FST author, and his comment was
that -32768 might validly be regarded by a compiler as an expression rather  
than as a literal.  Now -32768 = -(32768), and 32768 is an invalid INTEGER  
literal on the machines we are considering, so he has a point.  This does  
not seem to have been mentioned in the discussion yet.
  


--  
uucp: {mcvax!uunet,tektronix,sun!nosun}!oresoft!dawggon!2!490!19.101!Pat.Terry
Internet: Pat.Terry@p101.f19.n490.z2.fidonet.org

bartonr@psu-cs.cs.pdx.edu (Robert Barton) (05/13/89)

  Here is a summary of the results of WriteInt(-32768, 12):

 Compiler                         Version        Output

TDI Modula-2/Amiga                 3.01           8000H -4294934528
TDI Modula-2/ST                    2.30a
M2S M2Sprint Amiga                 1.00a           8000      -32768
ETH Modula-2 For Encore Multimax   2.00
Logitech Modula2/86                2.02            8000      -32768
Logitech Modula2/86                3.03            8000      -32768
M2Amiga                            3.2         FFFF8000      -32768
Oregon Software Xenix/386                      FFFF8000      -32768
Oregon Software Sun-3                          FFFF8000      -32768
Sun Modula-2                       2.1         FFFF8000      -32768

  The TDI ST compiler wouldn't accept the assignment int := -32768, giving
"this type is not expected".  The person with the ETH compiler got a run-time
range error.  He also mentioned that on his system MinInt was defined as
080000000H rather than 08000H, so I can't figure that one out.  The M2Amiga,
Oregon Software, and Sun compilers apparently use 32-bit INTEGER and CARDINAL.
I wonder how they handle WriteInt(-2147483648, 12) ?  Thanks to everyone
who responded.