09-13-2012 04:32 PM
Why is the data type of loop iterator a signed integer rather than an unsigned integer?
09-13-2012 04:41 PM
now this is a question I would like to know the answer.
When discussing with work colleagues we came to the possible conclusion that it was related to something in the very earlier versions of LabVIEW and has stuck ever since.
Be cool to get some input on this one
09-13-2012 05:44 PM - edited 09-13-2012 05:44 PM
I'd hazard a guess it'd be something to do with pre-initial conditions. So if t0 relied of t(-1), t(-2) etc, you could do it get the appropriate t-value with decrements rather than having to do nested first runs or something.
09-13-2012 06:31 PM
I32 is much more universal, and is for example used for array indices, array sizes, etc. The iteration terminal is most often connected to one of those functions. Your diagram would have the measles, with coercion dots all over without I32 on the iterator.
If you need to keep count with e.g. U32 or U64, you can make your own using a shift register and +1 function. 😄
(There are ideas to make the representation changeable according to your needs. See also my comment here)
09-13-2012 10:05 PM
@altenbach wrote:
Your diagram would have the measles, with coercion dots all over without I32 on the iterator.
Not if you make your coersion dots blue.
09-13-2012 11:29 PM - edited 09-13-2012 11:30 PM
I'll hazard a guess here.
Array indexing uses signed integers because a common calculation involves relative indexing (How far is this element from that element? or, What is the value of the element N past, or N before, this element?), which implies subtraction operations on two index values, which would be a real pain if we had to re-cast that delta index value.
And if we accept that array indicies should be signed, then logically the iteration terminal on loops must be too.
Dave
09-14-2012 06:02 AM - edited 09-14-2012 06:02 AM
It is also useful to have the special value -1, for instance when searching the array.
Basically here the sign bit is carring the result of the operation.
09-14-2012 06:34 AM
Altenbach and Marco hit the nail on its head.
Indeed, I32 was chosen be compatible to esp. array functions where a certain negative value has a significant meaning: -1
If you use Search 1D Array to find an element within an array, but that element is not present, the return value of the function is -1. So -1 indicates a "not found".
Integer values do not "know NaN (not a number)", so there is not much choice than to use negative numbers (since '0' is the first array element!).
hope this clears things up,
Norbert
09-14-2012 07:38 AM
@Norbert_B wrote:
Altenbach and Marco hit the nail on its head.
...
Norbert
While having dinner with one of the other contributors here I wa asked the same question and my reply to them was as mentioned above.
It is nice to get independent confirmation without asking for it.
Thank you!
Ben
09-15-2012 03:25 PM
Isn't the unspoken question here: "why are integers blue"?