[comp.sys.amiga] Demo of a sign bug in AmigaBASIC long integer multiplies

xanthian@well.UUCP (Kent Paul Dolan) (07/17/89)

Here is a little AmigaBASIC program to show off the sign bug in long integer
multiplies.  Think of it as a "caveat emptor" for potential buyers of Microsoft
products.  In my experience, this is entirely typical of their output.
-----cut here-----
REM Run under AmigaBASIC
REM This demo by Kent Paul Dolan, found at
REM P.O. Box 390755, Mountain View, CA 94039-755
REM
DIM a&(8),b&(4)
a&(1) = -65535&
a&(2) =  65535&
a&(3) = -65536&
a&(4) =  65536&
a&(5) = -32767&
a&(6) =  32767&
a&(7) = -32768&
a&(8) =  32768&
b&(1) = -1&
b&(2) =  1&
b&(3) = -2&
b&(4) =  2&
PRINT "Demo of a gross bug in Amigabasic signed long integer arithmetic"
PRINT "that has survived the revision from 1.1 to 1.2.
PRINT
PRINT "There should be no groups of output with all positive results in the"
PRINT "right hand column, but due to the long multiply sign bug, there are"
PRINT "two.  The other outputs are included to help classify the problem."
PRINT
PRINT "These calculations were all done with long integers."
PRINT
PRINT "You will need to click the mouse once in the output window before"
PRINT "pressing enter in response to the prompts."
PRINT
FOR i=1 TO 8
 FOR j=1 TO 4
  PRINT "a, b, a+b, a*b: ";
  PRINT a&(i);" ";b&(j);" ";a&(i)+b&(j);" ";a&(i)*b&(j)
 NEXT j
 INPUT "--Press enter for more data--",c$
NEXT i
PRINT
PRINT "This seems to occur whenever one long has a significant bit in the"
PRINT "two high order bytes and the other long is small enough that the"
PRINT "multiplication doesn't overflow.  In those cases, the result is"
PRINT "always positive, even when the right answer is negative."
PRINT
INPUT "--Press enter for credits and insult to guilty party--",c$
PRINT
PRINT "Thanks, Microcruft.  Your sterling quality control, keen workmanship,"
PRINT "and vast professional pride fill my heart with another dull thud!"
PRINT "[I don't suppose it was a big surprise when you failed to receive my"
PRINT "resume, yet again.]  Kent, the man from xanth, now at well!xanthian."
PRINT
INPUT "--Press enter to exit demo--",c$
END
-----cut here-----
well!xanthian
Kent, the man from xanth, now just another echo from The Well.