Microsoft KB Archive/86063

= FIX: F6099: Int Overflow Unreported on Exponential Math =

Article ID: 86063

Article Last Modified on 12/1/2003

-

APPLIES TO


 * Microsoft FORTRAN Compiler 4.0
 * Microsoft FORTRAN Compiler 4.01
 * Microsoft FORTRAN Compiler 4.1
 * Microsoft FORTRAN Compiler 5.0
 * Microsoft FORTRAN Compiler 5.1
 * Microsoft FORTRAN Compiler 4.1
 * Microsoft FORTRAN Compiler 5.0
 * Microsoft FORTRAN Compiler 5.1

-



This article was previously published under Q86063



SYMPTOMS
Programs compiled with Microsoft FORTRAN version 4.0, 4.01, 4.1, 5.0, or 5.1 with the /4Yb compiler option or the $DEBUG metacommand may not report the following run-time error message

run-time error F6099: $DEBUG

- INTEGER overflow

if an integer is raised to a power, which is an integer other than 2. If the exponent is a REAL number, the following error may be generated:

run-time error M6101: MATH

-floating-point error:invalid



CAUSE
The /4Yb compiler option or $DEBUG metacommand directs the compiler to do testing for INTEGER overflow, but it fails to do this for the exponential arithmetic if the exponent is an integer other than 2. If the exponent is 2, the algorithm is implemented as simple multiplication and the INTEGER overflow error is generated. In the case of REAL exponents, INTEGER overflow is still incorrectly not being checked; however, a floating-point math exception eventually is generated because intermediate values are being computed using floating-point values.



RESOLUTION
Code should be written to check INTEGERS that are raised to a power for overflow.



STATUS
Microsoft has confirmed this to be a problem in Microsoft FORTRAN versions 4.0, 4.01, 4.1, 5.0, and 5.1 for MS-DOS and OS/2. This problem was corrected in FORTRAN PowerStation, version 1.0.



MORE INFORMATION
The following code reproduces the problem:

Sample Code 1
$debug integer i, j, m

m = 500 do i=1,100000 j=m**i ! This line will not generate an INTEGER overflow.

k=(m+i*1000)**2 c This line will generate the overflow error because n**2 is c implemented as multiplication (n*n) and doesn't use exponentiation.

write(*,*) 'j=',j write(*,*) 'k=',k end do     end

Sample Code 2
The following code is an example of a way of avoiding INTEGER overflows. $debug integer i     real    max, check

max = huge(i) k = 500

do i=1,100000 check = max**float( 1./float(i) ) print*, i, check , k**i if (float(k).ge.check) stop 'Integer overflow' end do     end

Additional query words: 4.00 4.10 5.00 5.10 buglist5.00 buglist5.10 fixlist1.00

Keywords: kbfix KB86063

-

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

© Microsoft Corporation. All rights reserved.