Type
| Function |
Description
| The overloaded function TO_REAL converts an input value of various data types into an output value of the data type REAL (see description of the input for the supported data types). |
Parameters
| Input
IN
Data type: | The function is available for the following input data types:
- BOOL, DWORD
- Integers: SINT, INT, DINT, LINT, USINT, UINT, UDINT, ULINT
- Floating point numbers: LREAL
- STRING
|
Output
OUT
|
Conversion rules
| ANY_BIT conversion
The data type conversion of the source data type DWORD is done as binary transfer (bitwise copy from the source data type to the REAL data type). For the BOOL to REAL conversion, the input value FALSE results in 0.0 and the input value TRUE in 1.0.
ANY_INT conversion
The numeric value is converted into the REAL format according to the IEC 60559 standard. Here, the basic single width floating format is defined. Mantissa and exponent are set automatically.
LREAL conversion
When converting LREAL inputs to REAL values, the behavior in case of an overflow/underflow is target-specific.
DWORD conversion
The DWORD to REAL conversion complies with the latest standardization by the IEC 61131-3, 3rd edition. The floating point value is stored according to the IEEE 754 standard.
STRING conversion
- The string value has to be a valid numeric literal of the output data type, otherwise the function returns the value 0 and the runtime error 'Format string failure' occurs (see the note below).
- Additional characters except than whitespaces after or before the numeric literal are not permitted. The function returns the value 0 and generates a 'Format String Failure' if the string value contains unallowed characters.
- All leading and trailing whitespaces in the input string are ignored.ASCII codes regarded as whitespaces:
Character | Value |
Horizontal tab | 9 (09h) |
Line feed | 10 (0Ah) |
Vertical tab | 11 (0Bh) |
Form feed | 12 (0Ch) |
Carriage return | 13 (0Dh) |
Blank | 32 (20h) |
- If the input value is out of the range for the output data type, the overflow value is returned and the runtime error 'Format string failure' occurs (see the note below).
- Binary, octal, hexadecimal and decimal integers are allowed. For example:INT#2#0101 (binary representation of 5)INT#8#606 (octal representation of 390)INT#10#100 (decimal representation of 100)INT#16#00FA (hexadecimal representation of 250)
Note
Controller stop on string error: The controller can be automatically stopped when a string error occurs. This allows you to locate the error in your project. To enable the automatic stop of the controller in case of a string error, activate the button in the Cockpit toolbar of the controller. |
Note: If the range and precision of the input data type can be mapped to the range and precision of the output type, an implicit type conversion can be performed instead of using this function. For the TO_REAL function, this applies to INT, SINT, UINT and USINT inputs. |
Error behavior
| Error behavior
The following table shows the errors which may occur while executing the function and the value returned by the function in the corresponding error case. As described, the value returned by the function in the error case depends on the value of the input (for example, if the input value of data type LREAL is greater than REAL_MAX, the function returns the positive infinity value (inf+)).
Error case | Output value |
LREAL value > REAL_MAX | Inf+ |
LREAL value < REAL_MIN | Inf- |
Real: NaN | NaN |
Real: inf+ | Inf+ |
Real: Inf- | Inf- |
|
Additional information
| EN/ENO behavior
The POU is only executed if TRUE is applied to the EN input. If EN = FALSE, the POU is not executed and ENO = FALSE indicates the inactivity.
If any of the errors listed under "Error behavior" occurs while executing the function, ENO is set to FALSE.
|