Why does GCC use multiplication by a strange number in implementing integer division?

I’ve been reading about div and mul assembly operations, and I decided to see them in action by writing a simple program in C: File division.c #include <stdlib.h> #include <stdio.h> int main() { size_t i = 9; size_t j = i / 5; printf(“%zu\n”,j); return 0; } And then generating assembly language code with: gcc … Read more

Int division: Why is the result of 1/3 == 0?

The two operands (1 and 3) are integers, therefore integer arithmetic (division here) is used. Declaring the result variable as double just causes an implicit conversion to occur after division. Integer division of course returns the true result of division rounded towards zero. The result of 0.333… is thus rounded down to 0 here. (Note that the processor … Read more