LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

iteration a signed integer and not an unsigned integer, why?

Solved!
Go to solution

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

Message Edited by Ujjval Shah on 07-08-2009 09:21 AM
0 Kudos
Message 1 of 6
(2,991 Views)

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. 🙂

Message 2 of 6
(2,984 Views)

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 ? 🙂

0 Kudos
Message 3 of 6
(2,976 Views)
and again, why I32, when not U32 for i and N?
0 Kudos
Message 4 of 6
(2,967 Views)
Solution
Accepted by topic author Ujjval Shah

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.

Message 5 of 6
(2,966 Views)

ah nice, i get it now 🙂

thanks altenbach!

0 Kudos
Message 6 of 6
(2,929 Views)