Int to float

I took this course to learn how better use Raylib to try and create a 2d game because (for the most part) I understand C++; I jumped to this section because I wanted to try and make a 2d top-down game and so far, you have given me a lot of tips to help me move forward (such helping me better understand parts of the Raymath library)

I see you are casting integer values to float. Don’t integers get implicitly cast to float by the compiler anyways? (Like they do in C#.) if so, couldn’t you just use an integer when you require a float value with no decimal part, due to this implicit conversion? Are you doing this to make the code more readable, or is there some performance benefit that I am not aware of?

It really has to do with warnings you may get when not casting from the compiler. The interesting part about going from int to float is that you might actually lose data. As int has a higher precision than float does at very large values, so you may end up losing data if you cast an int as a float.

For game development purposes, though, you’re not likely to run into this. But since the compiler doesn’t know that it gives you a warning anyway.

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms