[previous] 3341 [next] Comparing floating point expressions for equality (with '==' or '!=').
Arithmetic type - Operations

Floating point operands are being compared with an equality operator (== or !=). Performing operations of this nature on floating point operands is dangerous because the representation of floating point values is generally an approximation.

For example:


/*PRQA S 2017,3227,3408 ++*/

int foo(float a, float b)
{
    int r = 0;


    if (a == b)                 /* Message 3341 */
    {
        r = 1;
    }

    return r;
}


MISRA-C:2004 Rules applicable to message 3341:

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


QA·C Source Code Analyser 8.1
MISRA-C:2004 Compliance Module 3.2
© 2012 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index Contents