Skip to main content

IAR Embedded Workbench for RX 5.20

MISRAC++2008-6-2-2

In this section:
Synopsis

(Required) Floating-point expressions shall not be directly or indirectly tested for equality or inequality.

Enabled by default

Yes

Severity/Certainty

Low/High

lowhigh.png
Full description

There are floating-point comparisons that use the == or != operators. This check is identical to ATH-cmp-float, MISRAC2004-13.3.

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.

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;
}