PLC-lang / rusty

Structured Text Parser and LLVM Frontend
GNU Lesser General Public License v3.0
223 stars 53 forks source link

Missing conversion functions #1117

Open volsa opened 8 months ago

volsa commented 8 months ago

Some missing conversion functions taken from an internal document:

ghaith commented 8 months ago

We need to define the exact behaviour of some of these functions. For example INT_TO_STRING would just be an alias for DINT_TO_STRING but LREAL_TO_DWORD is very strange to me, are we reading the LREAL value into a DINT and converting it to DWORD or are we reading the binary representation of the LREAL, in which case it does not fit in a DWORD and needs an LWORD, so LREAL_TO_DWORD should in that case not be supported.

tisis2 commented 8 months ago

IEC61131-3 6.6.2.5.3 see the tables e.g. for LREAL_TO_DWORD its defined that it is a binary transfer of the bits on the right side

ghaith commented 8 months ago

IEC61131-3 6.6.2.5.3 see the tables e.g. for LREAL_TO_DWORD its defined that it is a binary transfer of the bits on the right side

LREAL_TO_LWORD ist defined but LREAL_TO_DWORD is not only REAL_TO_DWORD at least in table 25. The problem with a binary transfer between LREAL and DWORD is that the result is not something you could use due to the internal representation of an LREAL. For example 1.0 in LREAL is 00111111 11110000 00000000 00000000 00000000 00000000 00000000 00000000 if we convert it to DWORD, it is just 0 same for 2.0, 3.0 .. (see https://www.binaryconvert.com/convert_double.html) LINT_TO_DWORD is defined as a binrary transfer because it just causes the loss of the left most bits.

tisis2 commented 8 months ago

you are right i think i mixed it up with other conversions