07-15-2022 12:16 PM - edited 07-15-2022 12:17 PM
I am attempting to sum the elements of the following array:
[0 10 14 16 20 22 22 24 25 26 26 26 28 28 28 28 27 26 26 26 25 24 22 21 19 16 13 8 0 0 0]. I have tried to do this 3 different ways and all display the same issue -- almost a glitch.
Tracing the LabVIEW code revealed the sum array elements feature (and a loop by hand -- version attached to provide more probing opportunities) both result in the incorrect sum of 84. It appears that the running total is reset twice during the summation process. Since this occurs both by a manual loop and by sum array elements how can I solve this issue? I cannot write a specific exception for this array case as this is a sub-VI for larger code.
The behavior of the code suggests there may be a bug in some LabVIEW VI's but I find this hard to believe as the earlier sum array elements worked perfectly.
Thank you!
LabVIEW 2021 SP1 64-bit Fresh install
Solved! Go to Solution.
07-15-2022 01:14 PM
U8 can only have numbers up to 255 and your sum exceeds that, causing wrapping according to the established rules of integer math. All you need is insert a conversion to a sufficient datatype (e.g. to I32) before summing.
07-15-2022 01:24 PM - edited 07-15-2022 02:17 PM
In addition, your code makes very little sense overall.
see if this can give you some ideas.
07-15-2022 01:41 PM
Thank you for the solution altenbach. I totally forgot U8 has a 255 limit.