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


No MISRA C:2012 Rules applicable to message 3341


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