27-06-2016, 12:23 PM
When a value of complex floating type is converted to a real floating type, the imaginary part is discarded (C99 6.3.17(2)) and the real part is converted according to the normal C conversion rules. The normal MISRA C:2012 guidelines apply to the conversion on the real part.
However the following would violate rule 10.3
When a value of real floating type is converted to a complex floating type, the imaginary part is given the value of 0 (C99 6.3.17(1)) and the real part is converted according to the normal C conversion rules. The normal MISRA C:2012 guidelines apply to the conversion on the real part.
More discussion on MISRA C:2012 handling of complex types can be found at http://www.misra.org.uk/forum/viewtopic.php?t=1273
Code:
d = fc; // permitted float -> double conversion
f = fc; // permitted no conversion required as float to float
Code:
double _Complex dc;
f = dc; // violates rule 10.3 since real part undergoes narrowing conversion.
When a value of real floating type is converted to a complex floating type, the imaginary part is given the value of 0 (C99 6.3.17(1)) and the real part is converted according to the normal C conversion rules. The normal MISRA C:2012 guidelines apply to the conversion on the real part.
Code:
fc = d; // violates rule 10.3 since real part undergoes narrowing conversion.
fc = f; // permitted no conversion required as float to float
Posted by and on behalf of the MISRA C Working Group