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

QA·C Source Code Analyser 8.1.2
© 2013 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index Contents