Consider non finite floats (-allow-non-finite-floats
)
Enable an analysis mode that incorporates infinities and NaNs
Description
Enable an analysis mode that incorporates infinities and NaNs for floating point operations.
Set Option
User interface (desktop products only): In your project configuration, the option is on the Check Behavior node.
User interface (Polyspace Platform, desktop products only): In your project configuration, the option is on the Static Analysis tab on the Run Time Errors > Check Behavior node.
Command line and options file: Use the option
-allow-non-finite-floats
. See Command-Line Information.
Why Use This Option
By default, the analysis does not incorporate infinities and NaNs. For instance, the analysis terminates the execution thread where a division by zero occurs and does not consider that the result could be infinite.
If you use functions such as isinf
or
isnan
and account for infinities and NaNs in your code,
set this option. When you set this option and a division by zero occurs for
instance, the execution thread continues with infinity as the result of the
division.
Set this option alone if you are sure that you have accounted for infinities and NaNs in your code. Using the option alone effectively disables many numerical checks on floating point operations. If you have generally accounted for infinities and NaNs, but you are not sure that you have considered all situations, set these additional options:
Infinities (-check-infinite)
: Usewarn-first
.NaNs (-check-nan)
: Usewarn-first
.
If the analysis flags comparisons using isinf
or
isnan
as dead code, use this option. By default, a Bug
Finder analysis does not incorporate infinities and NaNs.
Settings
- On
The analysis allows infinities and NaNs. For instance, in this mode:
The analysis assumes that floating-point operations can produce results such as infinities and NaNs.
By using options
Infinities (-check-infinite)
andNaNs (-check-nan)
, you can choose to highlight operations that produce nonfinite results and stop the execution threads where the nonfinite results occur. These options are not available for a Bug Finder analysis.The analysis assumes that floating-point variables with unknown values can have any value allowed by their type, including infinite or NaN. Floating-point variables with unknown values include volatile variables and return values of stubbed functions.
- Off (default)
The analysis does not allow infinities and NaNs. For instance, in this mode:
The Code Prover analysis produces a red check on a floating-point operation that produces an infinity or a NaN as the only possible result on all execution paths. The verification produces an orange check on a floating-point operation that can potentially produce an infinity or NaN.
The Code Prover analysis assumes that floating-point variables with unknown values are full-range but finite.
The Bug Finder analysis shows comparisons with infinity using
isinf
as dead code.
Tips
The IEEE® 754 Standard allows special quantities such as infinities and
NaN
so that you can handle certain numerical exceptions without aborting the code. Some implementations of the C standard support infinities andNaN
.If your compiler supports infinities and
NaN
s and you account for them explicitly in your code, use this option so that the verification also allows them.For instance, if a division results in infinity, in your code, you specify an alternative action. Therefore, you do not want the verification to highlight division operations that result in infinity.
If your compiler supports infinities and
NaN
s but you are not sure if you account for them explicitly in your code, use this option so that the verification incorporates infinities andNaN
s. Use the options-check-nan
and-check-infinite
with argumentwarn
so that the verification highlights operations that result in infinities andNaN
s, but does not stop the execution thread. These options are not available for a Bug Finder analysis.
If you run a Code Prover analysis and use this option, checkers for overflow, division by zero and other numerical run-time errors are disabled. See Numerical Checks (Polyspace Code Prover).
If you run a Bug Finder analysis and use this option:
These checkers are disabled:
Bug Finder defects:
Float conversion overflow
,Float division by zero
,Invalid use of standard library floating point routine
,Float overflow
.CERT C rules and recommendation: ,
CERT C: Rule FLP34-C
,CERT C: Rule FLP32-C
,CERT C: Rec. FLP03-C
,CERT C: Rec. FLP06-C
.CERT C++ rules:
CERT C++: FLP34-C
,CERT C++: FLP32-C
.AUTOSAR C++14 rule:
AUTOSAR C++14 Rule A0-4-4
.MISRA C:2004 rule: MISRA C:2004 rule 20.3.
These checker might show less violations:
MISRA C:2012 Dir 4.1
These checkers might show false positives:
Floating point comparison with equality operators
,AUTOSAR C++14 Rule M6-2-2
,MISRA C:2012 Dir 1.1
.
If you select this option, the number and type of Code Prover checks in your code can change.
For instance, in the following example, when you select the option, the results have one less red check and three more green checks.
Infinities and NaNs Not Allowed Infinities and NaNs Allowed Code Prover produces a Division by zero error and stops verification.
double func(void) { double x=1.0/0.0; double y=1.0/x; double z=x-x; return z; }
If you select this option, Code Prover does not check for a Division by zero error.
double func(void) { double x=1.0/0.0; double y=1.0/x; double z=x-x; return z; }
The analysis assumes that dividing by zero results in:
Value of
x
equal toInf
Value of
y
equal to 0.0Value of
z
equal toNaN
In your analysis results in the Polyspace® user interface, if you place your cursor on
y
andz
, you can see the nonfinite valuesInf
andNaN
respectively in the tooltip.
Command-Line Information
Parameter: -allow-non-finite-floats |
Default: Off |
Example (Bug Finder):
polyspace-bug-finder -sources |
Example (Code Prover):
polyspace-code-prover -sources |
Example (Bug Finder Server):
polyspace-bug-finder-server -sources |
Example (Code Prover Server):
polyspace-code-prover-server -sources |
Version History
Introduced in R2016a
See Also
Infinities (-check-infinite)
| NaNs (-check-nan)
| Numerical Defects | Numerical Checks (Polyspace Code Prover)