Microsoft KB Archive/38274

= Single Precision &quot;Overflow&quot; when Nearing Divide By Zero;10E-38 =

Article ID: 38274

Article Last Modified on 11/21/2006



This article was previously published under Q38274



SUMMARY
The code example below produces an &quot;OVERFLOW&quot; error at n = 38 for QuickBasic Versions 3.00, 4.00, and 4.00b, and Basic Compiler Versions 6.00 and 6.00b for MS-DOS and OS/2. The overflow occurs as you divide by ever larger numbers and approach the limits of the negative exponent for single precision. The program may overflow at different places in other versions of Basic. To work around the &quot;Overflow&quot; error, use at least one double precision variable or constant in the expression before assigning to the variable.



MORE INFORMATION
The following code example gives an &quot;Overflow&quot; error at n = 38: FOR n = 1 TO 100 x# = 1 / 10 ^ n PRINT n, x# NEXT In the above program, the expression 1/10^n is optimized to use single precision, since the most precise argument in the expression is n, which defaults to single precision.

To avoid the overflow of the negative single precision exponent, change n to double precision (n#). This forces the expression 1/10^n# to be stored in a double precision temporary storage area before being assigned to x#: FOR n# = 1 TO 100 ' This program runs fine from n#=1 through 100. x# = 1 / 10 ^ n# PRINT n#, x# NEXT

Additional query words: QuickBas BasicCom

Keywords: KB38274

-

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

© Microsoft Corporation. All rights reserved.