Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

E162 - Implicit integer to float conversion may lose precision

An integer is converted implicitly to a floating point type that cannot represent every value of the integer type. REAL represents integers up to 24 bits exactly, and LREAL up to 53 bits. Larger values are rounded.

Code example:

PROGRAM mainProg
VAR
    count : DINT := 16777217;
    value : REAL;
END_VAR
    value := count;     // warning: 16777217 becomes 16777216.0
END_PROGRAM

To silence the warning, convert explicitly:

    value := DINT_TO_REAL(count);

An integer passed to a generic function declared for ANY_REAL is converted the same way and warns as well. For the standard functions that are meant to take integers, such as SQRT and LN, this is a known false positive.