"Overflow" with Integer Division and MOD Operator; Workaround (58499)
The information in this article applies to:
- Microsoft QuickBASIC 4.0
- Microsoft QuickBASIC 4.0b
- Microsoft QuickBASIC 4.5
- Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.0
This article was previously published under Q58499 SUMMARY
The integer division operator (\) and the modulo arithmetic operator
(MOD) correctly produce an "Overflow" 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
Modification Type: | Minor | Last Reviewed: | 8/16/2005 |
---|
Keywords: | KB58499 |
---|
|