According to the same Javadoc:
If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument. Can't do that with an int.
The largest double value is also larger than the largest int, so it would have to be a long.
java - Why does Math.floor return a double? - Stack Overflow
java - (int) Math.floor(x / TILESIZE) or just (int) (x / TILESIZE) - Game Development Stack Exchange
Math.Floor
Why floor, round and ceil return double?
What is Math.floor JavaScript?
How to apply floor in Java?
Videos
According to the same Javadoc:
If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument. Can't do that with an int.
The largest double value is also larger than the largest int, so it would have to be a long.
It's for precision. The double data-type has a 53 bit mantissa. Among other things that means that a double can represent all whole up to 2^53 without precision loss.
If you store such a large number in an integer you will get an overflow. Integers only have 32 bits.
Returning the integer as a double is the right thing to do here because it offers a much wider usefull number-range than a integer could.
Personally, I would write the code just as:
unsigned int x
unsigned int y
public void myFunction()
{
getTile(x / 64, y / 64).doOperation();
}
since being a tilemap, you can use it (and thus assume) using positive-only values. This does not affect readability because x and y are declared as unsigned int, quite close to the block, and every programmer knows whether the language performs or not an integer division with the / operator when it is applied to two integers (most of them do). In fact, such a geometrical scenario is probably one of the few ones that shows that integer divisions can be useful.
Moreover, thinking about omptimization of such a snippet represents, in my opinion, one of those cases of "unnecessary preventive optimization": you can often assume that such operations will not be a bottleneck of your code, and thus take actions only when profiling shows the opposite. Performance of casting operations can be difficult to evaluate, in general: they largely depend not only on the language, but also on the compiler, which can remove unnecessary casts, or "translate" them in worse/better assembler.
I guess it safe to assume it is never negative, given that doing so would be reading outside the confine of the array. If that the case, simply rotate the bits 6 times which gives the same results but is far faster than using the int divide counterpart.
int x
int y
public void myFunction()
{
getTile(x >> 6, y >> 6).doOperation();
}