I'm trying to figure out if (int) floor(someNumber) will always give me the correct number. I know floats aren't usually represented exactly and I'm worried it will mess up the cast. Intuitively, floor(-2.3) == -3. What I'm afraid of is something like floor(-2.3) == -2.999999999124, which when cast will give me -2 instead of -3.
So the meat of the question is: does a float store integer numbers exactly, or approximated?
Depends.
Standard single precision IEEE numbers can store all integers in the absolute range [0;2^24) exactly.
Odd integers in the absolute range [2^24;2^25) cannot be represented.
Non-multiples of 4 in the absolute range [2^25;2^26) cannot be represented.
And so on.
floor() will always return a round integers, though.