I have noticed my floats are giving me headaches for 2 specific numbers (32 and 128) and i don't fully understand whats going on with these 2 numbers, also not sure how to fix it.
I print out these 2 lines:
var resA = (int) Math.Floor((a - o) / 1.0f);
var resB = (int) Math.Floor((b - o) / 1.0f);
Here is some examples:
var o = 0.795660f;
//test data
var a = 31.795660f;
var b = 32.795660f;
Output: resA : 31, resB: 31 ???
var a = 63.795660f;
var b = 64.795660f;
Output: resA : 63, resB: 64 // this is right
var a = 127.795660f;
var b = 128.795660f;
Output: resA : 127, resB: 127 ???
Every other number up to 256 works fine except 32 and 128 (though there might be more numbers beyond that).
So why does 2^5 and 2^7 give me the wrong answer, but every other number i tried worked fine.. whats so special about these 2 numbers that makes it fail?
Additionally how do you generally fix this problem ?