Issue
Internal counter stops counting.
Product Line
EcoStruxure Building OperationEnvironment
- Script
- Function Block
- Counter
- 167777216
Cause
When this script is used it stops counting at 16777216.
Numeric Output CountOut
Main:
CountOut = 16777100
goto Counter
Counter:
CountOut = CountOut + 1
Resolution
This issue was identified in the early days of Continuum and is regarded as a limitation, not a defect.
- Explanation - Internally the Script handles all numbers as IEEE754 single precision floats, which means that 16777216 is handled as 1.6777216E7. Adding 1 to 16777216 is unrecognizable in that representation.
- Using an IEEE754 converter at https://www.h-schmidt.net/FloatConverter/IEEE754.html, one can see that 16777216 and 16777217 have the same binary representation.
The point at which the counter will stop, will depend upon the value being added each time, so adding 0.9 will count to a different number than adding 1.
The counting range can be extended by two or more variables as shown below.
Numeric Output CountOut
Numeric CountOut1
Numeric CountOut2
Main:
CountOut1 = 16777100
goto Counter1
Counter1:
CountOut1 = CountOut1 + 1
CountOut = CountOut1
if CountOut1 = 16777216 then goto Counter2
Counter2:
CountOut2 = CountOut2 + 1
CountOut = CountOut1 + CountOut2