07-07-2009 10:50 PM - edited 07-07-2009 10:51 PM
i was just wondering if there is a reason for keeping the iteration variable/indicator of a loop a signed 32 bit integer.
it is never going to take a negative value.. then why signed; unsigned could have served the purpose
Solved! Go to Solution.
07-07-2009 11:21 PM
Remember that array sizes are limited to I32 (the "size" input to initialize array is I32, the output of Array size is I32, etc), so running a FOR loop more than 2^21 times is not even possible (N is also I32).
While loops can of course run forever, so if you need to increment a counter more than 2^31 times, you can use a shift register with U64, for example. However, don't even try to autoindex an output tunnel of such a loop, you're almost guaranteed to run out of memory before you reach the limits of I32.
Using array indices as I32 has several advantages. For example sometimes you need an invalid index (Integers don't have NaN!), so having a negative number is very useful. For example if you use "search array" and no match is found, the output is -1.
I suspect in the very long run these things will change. In another decade, all OSs will be 64bit or more and RAM will be mesured in TB. LabVIEW will need to evolve too to keep up. 🙂
07-07-2009 11:32 PM
hey altenbach,
thanks for the answer, i am quite convinced.
but wouldnt it have been better to introduce the NaN in integer than assigning one whole bit just for a -1?..
which and where else negative numbers are used?
or is there something more than what meets my wits ? 🙂
07-07-2009 11:42 PM
07-07-2009 11:52 PM
Ujjval Shah wrote:but wouldnt it have been better to introduce the NaN in integer than assigning one whole bit just for a -1?..
which and where else negative numbers are used?
or is there something more than what meets my wits ? 🙂
Integers use every single bit, meaning that every single bit combinations is a real value. It needs to be this way to support all features of integer math. For example if you take the difference between two U32s from tick counts, you get the correct elapsed time (as long as it is shorter than 2^32ms), even if the counter wrapped around between the two ticks.
Due to the representation of floating point numbers (sign, exponent, mantissa), we can define unusual bit combinations with a special meaning (NaN, -Inf, +Inf, etc.). This is not possible for integers.
07-08-2009 10:20 PM
ah nice, i get it now 🙂
thanks altenbach!