27-07-2010, 03:54 PM
Rule 13.3 does not permit testing a floating point expression against 0.0. As pointed out by William Forbes, there is an example of this non-compliant code fragment in the rule text.
The C Standard defines !E to be equivalent to (0 == E). Therefore, application of ! to an expression of floating point type is breaks the rule because it is equivalent to an equality comparison against 0.
In the expression (0 == E), if E has a floating-point type 0 would be implicitly converted from int to the floating-point type. Therefore, !E would break the spirit of Rule 10.1 (implicit conversions from an integer type) even though not directly breaking the rule.
The expression !E, where E has floating-point type, would also break Rule 12.6 (operands of logical operators should be effectively Boolean).
The C Standard defines !E to be equivalent to (0 == E). Therefore, application of ! to an expression of floating point type is breaks the rule because it is equivalent to an equality comparison against 0.
In the expression (0 == E), if E has a floating-point type 0 would be implicitly converted from int to the floating-point type. Therefore, !E would break the spirit of Rule 10.1 (implicit conversions from an integer type) even though not directly breaking the rule.
The expression !E, where E has floating-point type, would also break Rule 12.6 (operands of logical operators should be effectively Boolean).
Posted by and on behalf of the MISRA C Working Group