Microsoft KB Archive/58499

= &quot;Overflow&quot; with Integer Division and MOD Operator; Workaround =

Article ID: 58499

Article Last Modified on 8/16/2005

-

APPLIES TO


 * Microsoft QuickBasic 4.0
 * Microsoft QuickBASIC 4.0b
 * Microsoft QuickBasic 4.5 for MS-DOS
 * Microsoft BASIC Professional Development System 7.0

-



This article was previously published under Q58499



SUMMARY
The integer division operator (\) and the modulo arithmetic operator (MOD) correctly produce an &quot;Overflow&quot; error if an operand is a negative number less than -2,147,483,648 or a positive number greater than +2,147,483,647 (outside the limits for long integers).

The following program shows how to do integer division and modulo arithmetic when the size of an operand causes overflow: x# = 2147483648               ' numerator y# = 123                      ' denominator x# = INT(x# + .5)             ' round off the numerator y# = INT(y# + .5)             ' round off the denominator PRINT FIX(x# / y#)            ' Emulate integer division PRINT x# - ( y# * FIX(x# / y#) ) ' Emulate modulo arithmetic

Additional query words: QuickBas BasicCom

Keywords: KB58499

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.