lmulok Allows Overflow, but Gives No Message

Product Version(s): 3.20 3.3x
Operating System:   MS-DOS
Flags: ENDUSER | TAR50110 docerr
Last Modified: 18-AUG-1988    ArticleIdent: Q10393

Problem:
   The program fragment below demonstrates a problem with the lmulok
function. The value the function returns is correct. However, if you
try to write out the value of the product when lmulok returns false,
you get a data-format error at run time.
   The following is an example of input that causes the error:

   first integer4 >2000000
   second integer4 >2000000

   Notice that the multiplication is done without any errors, but
writing out the product causes a data format error.
   Also, note that the behavior of lmulok is specified in the
reference manual. I examined the example with SYMDEB and found that
whenever the multiplication overflows, lmulok sets the value of the
product to 16#80000000, i.e., (unsigned) 2^31. Of course, 16#80000000
is not a legal integer4 value.
   The following is a short example code:

   program xx(input,output);
   VAR I,J,PRODUCT : integer4;
   X : integer;
   RESULT : boolean;
   FUNCTION LMULOK(A,B:integer4; var c:integer4) : boolean; extern;
   begin
   writeln;
   write('first integer4 >');
   readln(i);
   write('second integer4 >');
   readln(j);
   RESULT := lmulok(i,j,product);
   WRITELN(I:20,j:20);
   writeln(product);
   WRITELN('RESULT = ',RESULT:5)
   end.

Response:
   This problem is the result of a documentation error on Page 240 of
the Version 3.32 "Microsoft Pascal Compiler Reference Manual."
   The routine lmulok is the routine ultimately called to perform the
multiplication in any integer4 product, e.g. the code generated for I
:= J * K;, where I,J,K:integer4, will invoke lmulok. You are given
access to this routine so you can perform an integer4 multiplication,
which overflows without having the program abort with a fatal run-time
error.
   The value of the product is well defined only in the case where the
product does not overflow, i.e., the return value of lmulok is true.
This process occurs because the overflow condition is generally
detected before the multiplication is complete and computation ceases
as soon as the overflow is detected. The documentation indicates that
the product is always computed and returned; this is clearly
incorrect.
