Registrations are now open. Join us today!
There is still a lot of work to do on the wiki yet! More information about editing can be found here.
Already have an account?

Microsoft KB Archive/34290

From BetaArchive Wiki
Knowledge Base

Negative Math/Overflow in Compiled Program; OK in Interpreter

Article ID: 34290

Article Last Modified on 11/21/2006


  • Microsoft QuickBasic 1.0
  • Microsoft BASIC Compiler 6.0b
  • Microsoft BASIC Interpreter 2.0
  • Microsoft BASIC Interpreter 2.1 for Macintosh
  • Microsoft BASIC Interpreter 3.0 for Macintosh

This article was previously published under Q34290


This information applies to Microsoft QuickBASIC Version 1.00, Microsoft BASIC Compiler Version 1.00, and Microsoft BASIC Interpreter Versions 2.00, 2.10, and 3.00 for the Apple Macintosh.

The compiler is more limited than the interpreter in handling numeric overflow and will, in certain circumstances, return negative or wrong values when intermediate calculations overflow. The compiler must decide at compile time which precision is appropriate for a given operation. The precision cannot be changed if it proves inadequate at run time. This difference is documented on Page 90 of the "Microsoft BASIC Compiler for Apple Macintosh" manual and Page 70 of the "Microsoft QuickBASIC for Apple Macintosh: User's Guide."


The following example demonstrates the difference:

   M% = 30000 : N% = 30000
   X! = M% + N%

Within the interpreter, this code produces the value 60000 for X!. The integer sum of the integer values M% and N% is automatically converted to the floating-point value X!.

The compiler is not able to make the same conversion when it turns your program into an application. Since the expression in the last statement contains only integer variables, the compiler generates object code to perform integer addition. However, the result is too large (greater than 32,767) to be handled as an integer, so an incorrect value (-5536) is printed.

Additional query words: MQuickB

Keywords: KB34290