Different values of variable calculation in value display variable and variable using the Cicode device

Hello, Everyone.

I'm testing various methods of calculation.

First.

Inserting calculation expressions into numeric expressions of value display object.

Second.

Using the Cicode device, insert the expression into the address of the variable.

Device Tag Name Type (Address)
Disk_PLC PE REAL / R200
Disk_PLC PE_Giga REAL / R300
Cicode ACC_C REAL / (PE + PE_Giga*1000000) 

I wrote the value including the decimal point in the 'PE' tag.

Question 1)

A value other than the actual written value is entered.

Why are the values I am writing and the actual display values different?

When I write 324567.450 for 'PE' Tag, displayed data is  234567.453

When I write 234567.100 for 'PE' Tag, displayed data is  234567.094

Question 2) 

There is a difference between the two values.

Why are two values different using the same calculation?

I am testing data consistency

Because of these results, I am now facing a big problem with the consistency test.

  • The problem is that you're reaching the limits of precision for 32-bit floating point values (Citect REAL data type). According to TN4858, a REAL is good for 7 digits of precision. So, with the number 3234567.453, you can only be guaranteed that 3234567 will be correct, but the decimal places may be off.

    You see the difference between the expression displayed on screen and the Cicode variable because Citect uses 64 bit floating point values for calculations. So, with your expression: PE + (PE_Giga * 1000000) it converts the 32-bit PE and PE_Giga values to 64-bit, then does the calculation as a 64-bit value and displays the correct result. 64-bit values have 15 digits of precision, so it could display a number like 3234567 with up to 4 accurate decimal places. However, for the Cicode variable tag, the result has to be copied back into a 32-bit variable so you lose precision.

    To test this, I created a REAL DISK_PLC tag named Result. I put a button on the page with the command: Result = PE + (PE_Giga * 1000000)

    I displayed the Result value on the page. When I clicked the button, I saw the same value in Result as I saw in Acc_C since they are both 32-bit values.

    Unfortunately, there is no 64-bit REAL datatype for variable tags in Citect.