7/4/2018 5:35 PM | |
Joined: 4/28/2015 Last visit: 4/4/2024 Posts: 52 Rating: (1) |
Hi, i have created one FB to addition 0.25 to a real variable, but when the variable become 4194304.0 the operation stops. I noticed that if addition 0.25001 or more, the operation continue normally. Why? I work whit TiaPortal V14SP1. I attach the scl file. Best regards.
Attachmenttest.zip (83 Downloads) |
7/5/2018 8:31 AM | |
Joined: 9/23/2005 Last visit: 4/26/2024 Posts: 4522 Rating: (698) |
There you can find the answer. |
Regards, |
|
This contribution was helpful to3 thankful Users |
7/5/2018 10:43 AM | |
Joined: 4/28/2015 Last visit: 4/4/2024 Posts: 52 Rating: (1) |
But why? The value is inside of the real data limits (see attach) Please, if you can, try my scl file, and after contact me again.
|
7/5/2018 11:14 AM | |
Joined: 4/28/2015 Last visit: 4/4/2024 Posts: 52 Rating: (1) |
In KOP language, it has the same behaviour (see attach) |
7/5/2018 11:45 AM | |
Joined: 12/4/2009 Last visit: 4/25/2024 Posts: 452 Rating: (134) |
Hi. This is due to floating point number arithmetic. Please check the following article: Analyzing the loss of significance in floating-point computations or simple search the Internet for a similar term. Floating point number format represents huge range of real numbers with a payload in the terms of accuracy loss. Always keep that in mind if you're about to use it for very large (or very small) number handling. Hope this helps. Regards. |
Last edited by: crazyCow at: 7/5/2018 11:50:02 AMIf this post actually helped, you may consider using the Rate button above. |
|
This contribution was helpful to1 thankful Users |
7/5/2018 3:49 PM | |
Joined: 8/31/2005 Last visit: 4/26/2024 Posts: 2197 Rating: (326) |
This is because the REAL Format is 1bit sign, 23bit fraction and 8 bit exponent in dual system.See https://en.wikipedia.org/wiki/Single-precision_floating-point_format) . Therefore, when you add the 0.25, the number has to be rounded to fit into the real format. And the .25 are lost while rounding. You can use LREAL instead of REAL. This will shift the problem to higher numbers |
|
|
This contribution was helpful to3 thankful Users |
Follow us on