Using Exception, Precision, and Rounding Parameters

This topic describes the exception, precision, and rounding parameters that you can use for the control word.

Exception Parameters

An exception is disabled if its bit is set to 1 and enabled if its bit is cleared to 0. If an exception is disabled (exceptions can be disabled by setting the flags to 1 with SETCONTROLFPQQ [IA-32 architecture only]), it will not generate an interrupt signal if it occurs. The floating-point process will return an appropriate special value (for example, NaN or signed infinity), but the program continues. You can find out which exceptions (if any) occurred by calling GETSTATUSFPQQ (IA-32 architecture only).

If errors on floating-point exceptions are enabled (by clearing the flags to 0 with SETCONTROLFPQQ [IA-32 architecture only]), the operating system generates an interrupt when the exception occurs. By default these interrupts cause run-time errors, but you can capture the interrupts with SIGNALQQ and branch to your own error-handling routines.

You should remember not to clear all existing settings when changing one. The values you want to change should be combined with the existing control word in an inclusive-OR operation (IOR) if you do not want to reset all options. For example:

USE IFPORT

INTEGER(2) control, newcontrol

CALL GETCONTROLFPQQ(control)

newcontrol = IOR(control,FPCW$INVALID)

! Invalid exception set (disabled).

CALL SETCONTROLFPQQ(newcontrol)

Note iconNote

The GETCONTROLFPQQ, SETCONTROLFPQQ, and GETSTATUSFPQQ routines only affect the x87 status register. They do not affect the MXCSR register (the control and status register for the Intel(R) SSE and Intel(R) SSE2 instructions).

Precision Parameters

On systems based on the IA-32 architecture, the precision bits control the precision to which the FPU rounds floating-point numbers. For example:

USE IFPORT

INTEGER(2) control, holdcontrol, newcontrol

CALL GETCONTROLFPQQ(control)

! Clear any existing precision flags.

holdcontrol = IAND(control, NOT(FPCW$MCW_PC))

newcontrol = IOR(holdcontrol, FPCW$64)

! Set precision to 64 bits.

CALL SETCONTROLFPQQ(newcontrol)

The precision options are mutually exclusive. If you set more than one, you may get an invalid mode or a mode other than the one you want. Therefore, you should clear the precision bits before setting a new precision mode.

Note iconNote

The GETCONTROLFPQQ and SETCONTROLFPQQ routines only affect the x87 status register. They do not affect the MXCSR register (the control and status register for the Intel(R) SSE and Intel(R) SSE2 instructions).

Rounding Parameters

On systems based on the IA-32 architecture, the rounding flags control the method of rounding that the FPU uses. For example:

USE IFPORT

INTEGER(2) status, control, controlo, mask_all_traps

CALL GETCONTROLFPQQ(control)

WRITE (*, 9000) 'Control word: ', control

>

! Save old control word

controlo = control

! Clear the rounding control flags

control = IAND(control,NOT(FPCW$MCW_RC))

! Set new control to round up

control = IOR(control,FPCW$UP)

CALL SETCONTROLFPQQ(control)

CALL GETCONTROLFPQQ(control)

WRITE (*, 9000) 'Control word: ', control

The rounding options are mutually exclusive. If you set more than one, you may get an invalid mode or a mode other than the one you want. Therefore, you should clear the rounding bits before setting a new rounding mode.

Note iconNote

The GETCONTROLFPQQ and SETCONTROLFPQQ routines only affect the x87 status register. They do not affect the MXCSR register (the control and status register for the Intel(R) SSE and Intel(R) SSE2 instructions).