MISRAC2012-Rule-10.1_R10
In this section:
Synopsis
(Required) The inherent nature of floating-point types is such that comparisons of equality will often not evaluate to true even when they are expected to.
Enabled by default
Yes
Severity/Certainty
Medium/Medium

Full description
An operand of essentially floating type is used as the operand to equal or not equal operator.
Coding standards
- MISRA C:2012 Rule-10.1
(Required) Operands shall not be of an inappropriate essential type
Code examples
The following code example fails the check and will give a warning:
void example(int n)
{
float f = 3.0f;
if (f == n); /* fail, comparison of a float and an int */
}
The following code example passes the check and will not give a warning about this issue:
void example(int n)
{
float f = 3.0f;
if (f > n); /* pass, comparison of a float and an int */
}