Industry Online Support
Technical Forum
10/17/2014 2:42 PM  
Joined: 7/1/2013 Last visit: 5/17/2023 Posts: 74 Rating: (2) 
Today I have faced strange issue with some real number stuck at value 6.710886e+007. Number is incremented this way: ThatNumber := ThatNumber + SomeOtherNumber; 0.0 < SomeOtherNumber < 4.0. Other than that, number is written few lines after in this way: IF ThatNumber <= 0 THEN ThatNumber := 1; END_IF; Maximum value of real is about 3.402823e+38. And after that it goes to minus max value. PLC: S7 1200  1212 Programming: Tia Portal V11 SP2 UPD 5 What can be reason for this? 
Last edited by: bosandzeros at: 10/21/2014 9:00 AM 

10/17/2014 2:48 PM  
Joined: 7/7/2010 Last visit: 6/8/2023 Posts: 13374 Rating: (2185)

What is the size of SomeOtherNumber? If you want to add real and integer values, you will be in the noise level of the real when the integer is in the noise level. Try using DINTs instead of REALs to increment or addnumbers together. The resolution of a REAL is not like it is in math. It has finite resolution, so it really only helps if you are multiplying or dividing REALs, or if the values being added/subtracted are in the same relative power of ten so that the sum/diff actually does something. Welcome to the limitations of the digital world. 
science guy 

10/17/2014 3:26 PM  
Joined: 7/1/2013 Last visit: 5/17/2023 Posts: 74 Rating: (2) 
SomeOtherNumber is real inside odata block. It should be 32 bits. Both numbers are of type real. Is there some good thread on internet about this subject ? I didn't understood well what you were talking about. Best regards. 
10/18/2014 1:40 AM  
Joined: 7/7/2010 Last visit: 6/8/2023 Posts: 13374 Rating: (2185)

http://en.m.wikipedia.org/wiki/Floating_point Read about the problems and look for a problem showing round off error and accuracy loss.

science guy 

10/21/2014 8:55 AM  
Joined: 7/1/2013 Last visit: 5/17/2023 Posts: 74 Rating: (2) 
Ok. Finally understood problem. I knew that there is some error in representing floating point numbers, but my ASSUMPTION was that it is much smaller, something about zero point few zeros something. Wikipedia thread says: "This is roundoff error. In extreme cases, the sum of two nonzero numbers may be equal to one of them". Well, this was my extreme case. Thank you huggy_d1 for help. Best regards. 
Follow us on