math - Objective c min max operation -


can explain me why code:

nsinteger = -1; nsuinteger x = 1; nslog(@"min = %lu", min(i, x)); nslog(@"max = %lu", max(i, x));; 

prints min = 1

max = 18446744073709551615

you compare 2 different types: signed (nsinteger) , unsigned (nsuinteger). min/max convert unsigned integer.

moreover, negative nsinteger printed %lu instead of %du. therefore see big number.

nsinteger = -1; nsuinteger x = 1; nslog(@"min = %ld", min(i, (nsinteger)x)); nslog(@"max = %ld", max(i, (nsinteger)x)); 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -