[previous] 4119 [next] Result of floating point operation cast to an integral type.
Arithmetic type - Operations REFERENCE - ISO:C90-6.2.1.3 Conversions - Floating and Integral

The result of a floating point calculation has been explicitly cast to an integral type.

In an operation like this, any fractional part of the floating value is simply discarded, i.e. the value is rounded towards zero, Is this the intended behaviour ?

For example:


/*PRQA S 3121,3198,3199,3203,3408,3447 ++*/

extern float  fta;
extern float  ftb;

extern void foo(void)
{
    int n;

    n = (int)fta;                           /*              */

    n = (int)(fta * ftb);                   /* Message 4119 */
    n = (int)(fta / ftb);                   /* Message 4119 */
    n = (int)(fta + ftb);                   /* Message 4119 */
    n = (int)(fta - ftb);                   /* Message 4119 */

    n = (fta * ftb);                        /* Message 3804 */
    n = (fta / ftb);                        /* Message 3804 */
    n = (fta + ftb);                        /* Message 3804 */
    n = (fta - ftb);                        /* Message 3804 */
}

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