PDA

View Full Version : uint or int


general_macbeth
07-08-2009, 07:06 PM
What exactly is the difference between int and uint, or rather when is one to be used instead of the other in AS3?

finaiized
07-08-2009, 07:50 PM
int- numbers from -2147483648 to 2147483648
uint- only positive numbers, but double the 2147483648
Numbers- support decimals, like 0.00000232

As a general rule, use int if you know the value, and numbers if you don't. A lot of people avoid uint because it is slow. Take a look at approximate execution times below:

int: 24-26ms
Number: 31-36ms
uint: 105-225ms

snickelfritz
07-08-2009, 09:33 PM
uint(unsigned integer) can only be a positive whole integer, such as "2".
int(integer) can be a positive or negative whole integer, such as "-2" or "2"

Personally, I use Number(any number, positive, negative or fractional) more often than either of the alternatives.
I use uint for hex color numbers, and pretty much nothing else.
Haven't found much use for int that can't be handled equally well by Number.

There's some information (http://www.gskinner.com/blog/archives/2006/06/types_in_as3_in.html) suggesting that uint is generally slower and more erratic for certain types of calculations than int or Number.