iphone: floats cast to unsigned ints get set to 0 if they are negative!?

Posted by matt on Stack Overflow See other posts from Stack Overflow or by matt
Published on 2010-03-22T07:40:53Z Indexed on 2010/03/22 7:41 UTC
Read the original article Hit count: 265

Filed under:
|
|

try it out:

volatile float bob = -344.0f;
unsigned int fred = (unsigned int)bob;

printf("%d\n",fred);

output will be 0.

obviously I am expecting it to wrap around just as if I had cast from a signed int to an unsgined int (which does wrap and act as expected on the iphone)

we assume it is something to do with the floating point settings.

any ideas?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about floating-point