FIX: F6099: Int Overflow Unreported on Exponential Math

Last reviewed: September 16, 1997
Article ID: Q86063
4.00 4.01 4.10 5.00 5.10 | 4.10 5.00 5.10
MS-DOS                   | OS/2
kbtool kbbuglist kbfixlist kberrmsg kbcode

The information in this article applies to:

  • Microsoft FORTRAN for MS-DOS, versions 4.0, 4.01, 4.1, 5.0, and 5.1
  • Microsoft FORTRAN for OS/2, versions 4.1, 5.0, and 5.1

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 reference words: 4.00 4.10 5.00 5.10 buglist5.00 buglist5.10
fixlist1.00
KBCategory: kbtool kbbuglist kbfixlist kberrmsg kbcode
KBSubcategory: FLIss
Solution Type : kbfix


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 16, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.