Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capacity of a uint64_t?

Tags:

objective-c

I have a little problem. Essentially, the code:

uint64_t myInteger = 98930 * 98930;
NSLog(@"%qu", myInteger);

...just gets it wrong. I get '1197210308' as the output, which is evidently incorrect. Why is this happening? It can't be that a uint64_t is too small, as they apparently go up to 18 and a half quintillion. Anyone have any idea?

like image 927
Ben Ward Avatar asked Jul 21 '10 20:07

Ben Ward


1 Answers

Try casting the first number so the operation is made using that type:

uint64_t myInteger = (uint64_t)98930 *98930;
like image 197
Mariano Desanze Avatar answered Sep 21 '22 02:09

Mariano Desanze