MISRA Discussion Forums
Floating point test for equality - 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.10 The essential type model (https://forum.misra.org.uk/forumdisplay.php?fid=165)
+---- Thread: Floating point test for equality (/showthread.php?tid=966)



Floating point test for equality - richardb - 26-06-2013

The previous MISRA version (2004) explicitly banned the use of tests for equality on floating point numbers (MISRA C 2004 rule 13.3).
MISRA C:2012 has a list of operands and essential types to avoid in the table in rule 10.1, but the use of the equality operator, ==, on the essential type floating is not restricted.
Could I suggest this is an unintentional omission?
Richard.


Re: Floating point test for equality - misra-c - 01-07-2013

The omission is quite deliberate!

Despite the logic of a simple, clear rule, the Working group were finding evidence that users were circumventing MISRA C:2004 rule 13.3 with constructs that were no "safer" than using the equality operator. The workaround was within the letter of the Rules, but quite clearly against the spirit - but the result was less maintainable code.

In MISRA C:2012, Directive 1.1 covers some of the generic aspects of using floating point - and as discussed in that Directive, there are many relevant issues and a project must decide how they wish to monitor the use of floating-point within the code produced by that project. Unfortunately there is no language subset that can be produced which avoids these issues.

Directive 4.1 also gives guidance on run-time failures - of which testing a floating-point number for equality is a likely candidate.