Handling Floating-Point Exceptions in FORTRAN

Last reviewed: December 11, 1995
Article ID: Q57918
The information in this article applies to:
  • Microsoft FORTRAN for MS-DOS, versions 3.3, 3.31, 4.0, 4.01, 4.1, 5.0, 5.1
  • Microsoft FORTRAN for OS/2, versions 4.1, 5.0, 5.1
  • Microsoft FORTRAN PowerStation 1.0, 1.0a for MS-DOS.
  • Microsoft FORTRAN PowerStation 32, versions 1.0 and 4.0

SUMMARY

The IEEE floating point standard defines the following five exceptions: invalid operation, divide by zero, overflow, underflow, and precision. The Microsoft FORTRAN run-time libraries provide the following three routines to obtain and modify the value of the status and control words:

  • The store-status-word (SSWRQQ) function returns the value of the status word.
  • The store-control-word (SCWRQQ) function returns the value of the control word.
  • The load-control-word (LCWRQQ) function sets the control word to a specified value.

An application can specify the manner to handle an exception by changing the control word and can determine which exceptions have occurred by checking the value of the status word.

MORE INFORMATION

The following code example demonstrates using the LCWRQQ function to disable the overflow and divide by zero exceptions and their corresponding run-time errors.

Sample Code

C Compile options needed: None

      INTERFACE TO SUBROUTINE LCWRQQ(CW)
      INTEGER*2 CW
      END

      PROGRAM NOEXCEPTIONS

      INTEGER*2 CW
      PARAMETER(CW = 16#133F)
      REAL*4 X, Y, Z

      X = 1.0
      Y = 0.0

      CALL LCWRQQ(CW)

      Z = X / Y

      END

NOTE: In FORTRAN PowerStation, GETSTATUSFPQQ is equivalent to SSWRQQ, GETCONTROLFPQQ is equivalent to SCWRQQ, and SETCONTROLFPQQ is equivalent to LCWRQQ.


Additional reference words: kbinf 1.00 3.30 4.00 4.10 5.00 5.10
KBCategory: kbprg kbcode
KBSubcategory: FORTLngIss


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: December 11, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.