MISRAC2004-13.3
In this section:
Synopsis
(Required) Floating-point expressions shall not be tested for equality or inequality.
Enabled by default
Yes
Severity/Certainty
Low/High

Full description
Floating-point comparisons using == or != were found. This check is identical to ATH-cmp-float, MISRAC++2008-6-2-2.
Coding standards
- CERT FLP06-C
Understand that floating-point arithmetic in C is inexact
- CERT FLP35-CPP
Take granularity into account when comparing floating point values
- MISRA C:2004 13.3
(Required) Floating-point expressions shall not be tested for equality or inequality.
- MISRA C++ 2008 6-2-2
(Required) Floating-point expressions shall not be directly or indirectly tested for equality or inequality.
Code examples
The following code example fails the check and will give a warning:
int main(void)
{
float f = 3.0;
int i = 3;
if (f == i) //comparison of a float and an int
++i;
return 0;
}
The following code example passes the check and will not give a warning about this issue:
int main(void)
{
int i = 60;
char c = 60;
if (i == c)
++i;
return 0;
}