Clearing the Coprocessor Status Word from FORTRAN

Last reviewed: July 31, 1997
Article ID: Q35434
4.00 4.01 4.10 5.00 5.10 1.00 1.00a | 4.10 5.00 5.10 | 1.00 4.00
MS-DOS                              | OS/2           | WINDOWS NT
kbprg 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, 5.1
  • Microsoft FORTRAN PowerStation for MS-DOS, versions 1.0 and 1.0a
  • Microsoft FORTRAN PowerStation 32 for Windows NT, version 1.0 and 4.0

SUMMARY

Page 17 of the Microsoft FORTRAN "Advanced Topics" manual for version 5.1 includes the following statement:

   When one of the floating-point exception conditions given in Table
   1.2 above occurs, the appropriate bit in the status word is set.
   This flag remains set until you clear it.

While the GETSTATUSFPQQ and SSWRQQ subroutines returns the value of the status word, there is no FORTRAN function or subroutine that will modify the status word.

MORE INFORMATION

Under normal circumstances, when the math coprocessor generates a floating-point exception, an exception handler is called which can clear the status word. If it is necessary to reset the control word at another time, the FORTRAN run-time library provides the C functions _clear87 and _fpreset which an application can access using an INTERFACE statement. The _clear87 function returns the value of the status word before changing the status word; the _fpreset subroutine resets the status word and returns no value.

The _clear87 and _fpreset functions might be useful when an application spawns another application that might perform a floating- point operation. When the spawned application completes execution, call the _clear87 or _fpreset function to return the floating-point environment to its default state. The following code example demonstrates using the _clear87 and _fpreset functions from FORTRAN.

NOTE: The sample code below will not link using FORTRAN's 32-bit linker due to a change in libc.lib. It no longer contains the function __clear87. Under the 32-bit FORTRAN compilers, the C function __clear87 is replaced by __clearfp.

Sample Code

C Compiler options required: None

      INTERFACE TO SUBROUTINE FPRESET[C, ALIAS:'__FPRESET']
      END
      INTERFACE TO INTEGER*2 FUNCTION CLEAR87[C, ALIAS:'__CLEAR87']
      END

      INTEGER*2 CLEAR87

      PRINT '(1X, A, Z)', 'INITIAL STATUS WORD:         ', CLEAR87()
      X = 1.E-38
      X = X / 100.
      PRINT '(1X, A, Z)', 'STATUS WORD AFTER UNDERFLOW: ', CLEAR87()
      CALL FPRESET
      PRINT '(1X, A, Z)', 'STATUS WORD AFTER _FPRESET:  ', CLEAR87()
      END


Additional reference words: 1.00 4.00 4.01 4.10 5.00 5.10 8087 80287 80387
80487 status exception kbinf
KBCategory: kbprg kbcode
KBSubcategory: FORTLngIss
Keywords : FORTLngIss kbcode kbprg
Version : 4.00 4.01 4.10 5.00 5.10 1.00 1.
Platform : MS-DOS NT OS/2 WINDOWS


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: July 31, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.