Pretty simple question really. I have two uint64 values. I want to divide the two numbers and get the remainder.
uint64 number1 = 36556800;
uint64 number2 = 59325441;
uint64 result = number1 % number2;
NSLog(@"Result: %lld", result);
The above code always prints the value of number1 (36556800).
EDIT: I realize that number1 is less than number2. When you divide these two numbers the result is a fraction. I want to capture that fraction. So basically in my example:
36556800 / 59325441 = 0.6162
How do I get 6162 into a variable? Integer division discards the fraction so isn’t the modulus operator what I should be using?
How many times does 59325441 go into 36556800?
Zero times, because 59325441 is greater than 36556800.
How much is left when you subtract 0 * 59325441 from 36556800?
Therefore
Your code is printing the correct answer. If you expected a different answer, edit your question to include the answer you expected, and explain why you expected it.
UPDATE
Based on your revised question, it sounds like you want to convert your numbers to
doublebefore you divide:Note that a
doublecannot represent all integers larger than 253 exactly.