fpt and WinFPT Reference Manual - Command-line Commands

| SimCon Home | Ref Manual Home |

PROTECT AGAINST DIVISION BY ZERO

Syntax:

[DO NOT] PROTECT AGAINST DIVISION BY ZERO

Motivation

Some systems, in particular the Gould-SEL Concept series machines which are widely used for manned flight simulators with motion, do not halt when a division by zero occurs. This is a safety feature. When the codes are migrated to standard systems it is sometimes important to retain this behaviour.

Function:

fpt replaces explicit divisions in the code by function calls which carry out the divisions, but which take specific actions to prevent the program from crashing when a division by zero is attempted. Divisions are replaced only when the denominator is a variable or variable expression. Divisions by constants are not changed, but an error is issued if the constant evaluates to zero.

Please note also that only explicit divisions are modified. The code of expressions containing the intrinsic functions MOD and ATAN2, for example, is not changed.

The functions called to carry out the divisions are:

protected_divide_i1 protected_divide_i2 protected_divide_i4 protected_divide_i8 protected_divide_r4 protected_divide_r8 protected_divide_r16

Where the numerator and denominator are of different data types and sizes intrinsic function calls are inserted to convert the function arguments to the highest kind and to REAL if the other argument is REAL.

The protected divide functions reside in the sub-directory fpt_lib below the main fpt directory. Users may substitute their own functions to take actions appropriate to the application in use.

The functions in the distributed library test the denominator against a criterion value. This is zero in the case of integer divisions and for real divisions is the appropriate Fortran parameter declared in the file pd_cmn.inc in the fpt_lib directory. If the magnitude of the denominator is equal to or less than the criterion, the function returns a signed result of magnitude defined by parameters in pd_cmn.inc. The real criteria and the integer and real results are:

REAL*4 protected_divide_crit_r4 REAL*8 protected_divide_crit_r8 REAL*16 protected_divide_crit_r16 INTEGER*1 protected_divide_result_i1 INTEGER*2 protected_divide_result_i2 INTEGER*4 protected_divide_result_i4 INTEGER*8 protected_divide_result_i8 REAL*4 protected_divide_result_r4 REAL*8 protected_divide_result_r8 REAL*16 protected_divide_result_r16 PARAMETER (protected_divide_crit_r4=1.0e-10) PARAMETER (protected_divide_crit_r8=1.0d-10) PARAMETER (protected_divide_crit_r16=1.0q-10) PARAMETER (protected_divide_result_i1=127) PARAMETER (protected_divide_result_i2=32767) PARAMETER (protected_divide_result_i4=2147483647) PARAMETER (protected_divide_result_i8=9223372036854775807) PARAMETER (protected_divide_result_r4=1.0e10) PARAMETER (protected_divide_result_r8=1.0d10) PARAMETER (protected_divide_result_r16=1.0q10)

The lines relating to REAL*16 and INTEGER*8 quantities are commented out for some hosts, and INTEGER*1 may be written as BYTE. Users may, of course, modify these files and change the values.

Where to Use this Command

Operating system command line Yes
Configuration file, config.fsp Yes
Specification (fsp) files, *.fsp Yes
Interactively, to FPT> prompt Yes
Interactive command files Yes
Embedded in the Fortran code Yes

Default

fpt does not protect against division by zero by default.

Examples

Code before modification:

s=q+y/(1+x)

After modification

s=q+protected_divide_r4(y,(1+x))

Copyright ©1995 to 2025 Software Validation Ltd. All rights reserved.