REAL/LREAL

The data types REAL and LREAL are floating-point types according to IEEE 754. They are necessary for the use of decimal numbers and floating-point numbers in point representation or exponential representation.

Data type

Lower limit

Upper limit

Smallest absolute value

Storage space

REAL

-3.402823e+38

3.402823e+38

1.0e-44

32-bit

LREAL

-1.7976931348623158e+308

1.7976931348623158e+308

4.94065645841247e-324

64-bit

Sample

PROGRAM MAIN
VAR
    fMaxReal     : REAL  := 3.402823E+38;              // Largest REAL number
    fPosMinReal  : REAL  := 1.0E-44;                   // Smallest positive REAL number
    fNegMaxReal  : REAL  := -1.0E-44;                  // Largest negative REAL number
    fMinReal     : REAL  := -3.402823E+38;             // Smallest REAL number

    fMaxLreal    : LREAL := 1.7976931348623157E+308;   // Largest LREAL number
    fPosMinLreal : LREAL := 4.94065645841247E-324;     // Smallest positive LREAL number
    fNegMaxLreal : LREAL := -4.94065645841247E-324;    // Largest negative LREAL number
    fMinLreal    : LREAL := -1.7976931348623157E+308;  // Smallest LREAL number
END_VAR
REAL/LREAL 1:

If the value of the REAL/LREAL number lies outside of the value range of the integer, an undefined result will be delivered when converting the data type from REAL or LREAL to SINT, USINT, INT, UINT, DINT, UDINT, LINT or ULINT.

REAL/LREAL 2:

Allocation of a particularly large literal

In order to assign an integer literal that is larger than the upper limit of ULINT, either a comma must be set or an explicit typecast must be specified. Without such a specification as a floating-point number, information can be lost.
Example:
fMyReal : REAL := 3400000000000000000000.0;
fMyReal : REAL := REAL#3400000000000000000000;

See also: