FOR_SET_FPE

Run-Time Function: Sets the floating-point exception flags. This routine can be called from a C or Fortran program.

Module

USE IFCORE

Syntax

result = FOR_SET_FPE (a)

a

Must be of type INTEGER(4). It contains bit flags controlling floating-point exception trapping, reporting, and result handling.

Results

The result type is INTEGER(4). The return value represents the previous settings of the floating-point exception flags. The meanings of the bits are defined in the IFCORE module file.

To get the current settings of the floating-point exception flags, use FOR_GET_FPE.

Example

USE IFCORE
INTEGER*4 OLD_FPE_FLAGS, NEW_FPE_FLAGS
OLD_FPE_FLAGS = FOR_SET_FPE (NEW_FPE_FLAGS)

The following example program is compiled without any fpe options. However, it uses calls to for_set_fpe to enable the same flags as when compiling with option fpe:0. The new flags can be verified by compiling the program with option -fpe:0.

   program samplefpe
   use ifcore
   implicit none

   INTEGER(4) :: ORIGINAL_FPE_FLAGS, NEW_FPE_FLAGS
   INTEGER(4) :: CURRENT_FPE_FLAGS, PREVIOUS_FPE_FLAGS
   NEW_FPE_FLAGS = FPE_M_TRAP_UND + FPE_M_TRAP_OVF + FPE_M_TRAP_DIV0  &
     + FPE_M_TRAP_INV + FPE_M_ABRUPT_UND + FPE_M_ABRUPT_DMZ
   ORIGINAL_FPE_FLAGS = FOR_SET_FPE (NEW_FPE_FLAGS)
   CURRENT_FPE_FLAGS = FOR_GET_FPE ()

   print *,"The original FPE FLAGS were:"
   CALL PRINT_FPE_FLAGS(ORIGINAL_FPE_FLAGS)
   print *," "
   print *,"The new FPE FLAGS are:"
   CALL PRINT_FPE_FLAGS(CURRENT_FPE_FLAGS)

!! restore the fpe flag to their original values
   PREVIOUS_FPE_FLAGS = FOR_SET_FPE (ORIGINAL_FPE_FLAGS)

   end

   subroutine PRINT_FPE_FLAGS(fpe_flags)
   use ifcore
   implicit none
   integer(4)   :: fpe_flags
   character(3) :: toggle

   print 10, fpe_flags, fpe_flags
10 format(X,'FPE FLAGS = 0X',Z8.8," B'",B32.32)

   if ( IAND(fpe_flags, FPE_M_TRAP_UND) .ne. 0 ) then
     toggle = "ON"
   else
     toggle = "OFF"
   endif
   write(*,*) "  FPE_TRAP_UND    :", toggle

   if ( IAND(fpe_flags, FPE_M_TRAP_OVF) .ne. 0 ) then
     toggle = "ON"
   else
     toggle = "OFF"
   endif
   write(*,*) "  FPE_TRAP_OVF    :", toggle

   if ( IAND(fpe_flags, FPE_M_TRAP_DIV0) .ne. 0 ) then
     toggle = "ON"
   else 
     toggle = "OFF"
   endif
   write(*,*) "  FPE_TRAP_DIV0   :", toggle

   if ( IAND(fpe_flags, FPE_M_TRAP_INV) .ne. 0 ) then
     toggle = "ON"
   else
     toggle = "OFF"
   endif
   write(*,*) "  FPE_TRAP_INV    :", toggle

   if ( IAND(fpe_flags, FPE_M_ABRUPT_UND) .ne. 0 ) then
     toggle = "ON"
   else
     toggle = "OFF"
   endif
   write(*,*) "  FPE_ABRUPT_UND  :", toggle

   if ( IAND(fpe_flags, FPE_M_ABRUPT_OVF) .ne. 0 ) then
     toggle = "ON"
   else
     toggle = "OFF"
   endif
   write(*,*) "  FPE_ABRUPT_OVF  :", toggle

   if ( IAND(fpe_flags, FPE_M_ABRUPT_DMZ) .ne. 0 ) then
     toggle = "ON"
   else
     toggle = "OFF"
   endif
   write(*,*) "  FPE_ABRUPT_DIV0 :", toggle

   if ( IAND(fpe_flags, FPE_M_ABRUPT_DIV0) .ne. 0 ) then
     toggle = "ON"
   else
     toggle = "OFF"
   endif
   write(*,*) "  FPE_ABRUPT_INV  :", toggle

   if ( IAND(fpe_flags, FPE_M_ABRUPT_DMZ) .ne. 0 ) then ! ABRUPT_DMZ
     toggle = "ON"
   else
     toggle = "OFF"
   endif
   write(*,*) "  FPE_ABRUPT_DMZ  :", toggle, "  (ftz related)"

   end subroutine PRINT_FPE_FLAGS

The output from this program is as follows:

>ifort set_fpe_sample01.f90
>set_fpe_sample01.exe
 The original FPE FLAGS were:
 FPE FLAGS = 0X00000000 B'00000000000000000000000000000000
   FPE_TRAP_UND    :OFF
   FPE_TRAP_OVF    :OFF
   FPE_TRAP_DIV0   :OFF
   FPE_TRAP_INV    :OFF
   FPE_ABRUPT_UND  :OFF
   FPE_ABRUPT_OVF  :OFF
   FPE_ABRUPT_DIV0 :OFF
   FPE_ABRUPT_INV  :OFF
   FPE_ABRUPT_DMZ  :OFF (ftz related)
 The new FPE FLAGS are:
 FPE FLAGS = 0X0011000F B'00000000000100010000000000001111
   FPE_TRAP_UND    :ON
   FPE_TRAP_OVF    :ON
   FPE_TRAP_DIV0   :ON
   FPE_TRAP_INV    :ON
   FPE_ABRUPT_UND  :ON
   FPE_ABRUPT_OVF  :OFF
   FPE_ABRUPT_DIV0 :ON
   FPE_ABRUPT_INV  :OFF
   FPE_ABRUPT_DMZ  :ON (ftz related)

Submit feedback on this help topic

Copyright © 1996-2010, Intel Corporation. All rights reserved.