MISRA Discussion Forums
Side effects in floating point comparisons - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: MISRA C:2012 and MISRA C:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=21)
+---- Forum: 8.13 Side effects (https://forum.misra.org.uk/forumdisplay.php?fid=168)
+---- Thread: Side effects in floating point comparisons (/showthread.php?tid=1597)



Side effects in floating point comparisons - gdavis - 13-01-2022

Hello,

A user is surprised that his compiler diagnoses the following as being a violation of MISRA 2012 13.5:

int in_range(double a)
{
    int result = 0;
    if (a >= 10.0 && a <= 20.0) {
        result = 1;
    }
    return result;
}

The reasoning behind the diagnostic is that with C99, floating point status bits (if implemented) are considered part of the program state, so floating point operations have implicit side effects.  See the footnote in C99 5.1.2.3.


This kind of goes back to Directive 1.1 and various decisions about floating point.

Does everyone agree that this should be considered a violation?  I would appreciate any other thoughts you may have.

Thanks,

-Greg


RE: Side effects in floating point comparisons - misra-c - 13-02-2022

Thank you for bringing this to our intention.  It was not our intention that floating point status bits were included in our definition of "persistent side effects".  This will be clarified in a later version.