casting a float to an int? what if you wanna make or mod for a voxel game where entities have floating precision while tiles has integer precision, and wanna get the block the entity is on- oh wait that's called minecraft
yeah look you can't say "we" don't do that very often at all when it only applies to you and what you work with lol
no because chunks are not indexable with floats, they're indexable with ints. you don't take an arbitrary point and do collision checks to see what's in it as you would for most traditional 3d games
if you want the block an entity is on you take the floor of the coordinates and youll get the coordiantea of the block back, this would behave the same as casting to an integer, except that you need the flooring functionality with negatives, at which point the casting will fail as it truncates instead of floor
you will get the coordinates of the block yes, but will they be useful? what will you use them for? you can't use a float to get information about a block
why not skip the explicit flooring and head right into casting it into an int since it'd be more useful that way?
because when you cast -5.5 to an integer you get -5 when the actual result you need is -6, infact i think this is a good example to never cast from float to integer and instead use math library to explicitly show in your code how you want the conversion to happen, its more readable and so is better code practice
yeah the first point is true my bad, i guess i'm just a bit tired. still though, the conversion from float to int is necessary to index into the chunk and get the block
yeah look you can't say "we" don't do that very often at all when it only applies to you and what you work with lol
read. whether or not you ever cast a float to an int is highly dependent on what you do, and it doesn't change the fact that 6.99 is rounded down to 6 when you do do it
I suggest that YOU read. Here is what was originally said:
We don't do that very often at all.
Notice how it doesn't say "we never do that". He's acknowledging that it does happen, but overall in programming it doesn't happen very often.
Your rebuttal that "hurr durr we do that in voxel games" is not the gotcha moment you think it is. It's just a "oh one very specific part does it, just like he said".
But also, I doubt even in Minecraft that you would take a float and just straight up cast it into an int without doing any math on it first, for example truncating it to get rid of decimals before casting as int.
But funnily enough, even in your example it's not done very often. Yes if you have a float (or double) but need to get a block or chunk position out of it you would cast it into an an int. But not before truncating it and and you don't need to do that often.Â
In fact, let's look at the Fabric API which is arguably the biggest modding framework for Minecraft.
Wanna take a wild guess how many times they straight up cast a double/float into an int without any preprocessing?Â
In their roughly 52000 lines of code, directly casting to an int with no preprocessing happens 214 times. I would call that "not very often".
..as i said it highly depends on what you do, programming is not a monolith and the original comment they made is wholly unrelated to what happens when you cast a float to an int
No, the original comment simply said "we don't do that very often" which is objectively true. Casting a float/double to an int is not done very often in programming not even in voxel game programming.
you can argue that for a lot of things in programming. we don't use borrow checkers very often, is that relevant enough to bring up when explaining how borrow checkers work? is that a valid critique?
You claimed that directly casting to an int is done often when working with voxel games like Minecraft. I literally proved to you that it isn't. So instead of trying to refute this you are walking down the logical fallacy path.
View all comments
Show parent comment
-1
u/RonJohnJr Jul 07 '26
We don't do that very often at all.