FPT and WinFPT Reference Manual - Command-line Commands
| SimCon Home | Reference Manual Home |
Syntax:
[DO NOT] PROTECT AGAINST DIVISION BY ZERO |
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:
Function | Operands |
PROTECTED_DIVIDE_I1 | INTEGER*1 |
PROTECTED_DIVIDE_I2 | INTEGER*2 |
PROTECTED_DIVIDE_I4 | INTEGER*4 |
PROTECTED_DIVIDE_I8 | INTEGER*8 |
PROTECTED_DIVIDE_R4 | REAL*4 |
PROTECTED_DIVIDE_R8 | REAL*8 |
PROTECTED_DIVIDE_R16 | REAL*16 |
Where the numerator and denominator are of different data types and sizes, intrinsic function calls are inserted to convert the function arguments.
The protected divide functions reside in the sub-directory fpt_lib below the main FPT directory, for example, C:\Program Files\SimCon\FPT37\fpt_lib for FPT version 3.7 on a Windows XP system with the default installation path. 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.
Example:
Code before modification:
S=Q+Y/(1+X)
After modification
S=Q+PROTECTED_DIVIDE_R4(Y,(1+X))
Copyright ©1995 to 2014 Software Validation Ltd. All rights reserved.