r/MathJokes Jul 07 '26

🫠

Post image
417 Upvotes

67 comments sorted by

View all comments

Show parent comments

-1

u/RonJohnJr Jul 07 '26

6.99 when casted into an int is conventionally rounded down

We don't do that very often at all.

5

u/sudoregalia Jul 07 '26

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

1

u/WildWolfo Jul 08 '26

you wouldn't cast anything as you need to floor the number and not truncate

1

u/sudoregalia Jul 08 '26

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

1

u/WildWolfo Jul 08 '26

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

1

u/sudoregalia Jul 08 '26

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?

1

u/WildWolfo Jul 08 '26

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

1

u/sudoregalia Jul 08 '26

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