Aug 15, 2016 at 5:08am Aug 15, 2016 at 5:08am UTC
I am dividing numbers like this:
1 2
int cx = x / width*32;
int cy = y / height*32;
Width and height are both 64. x and y are 600. The problem should be 600/2048 and I am expecting a result of zero, but cx and cy contain the value 288 after the operation. Why is this?
Last edited on Aug 15, 2016 at 5:08am Aug 15, 2016 at 5:08am UTC
Aug 15, 2016 at 5:16am Aug 15, 2016 at 5:16am UTC
integer division means that 2/3 = 0 cast the denominator to double or float is one easy way of coping with this drama :)
Aug 15, 2016 at 5:40am Aug 15, 2016 at 5:40am UTC
Oops I missed the reference to 288, story of my life.
Aug 15, 2016 at 2:46pm Aug 15, 2016 at 2:46pm UTC
Thanks Borges! What an easy fix. I feel silly now.