Computer math sometimes doesn't match actual math.
Especially when the compiler has optimized out something that affects the result of a calculation.
I've got a couple of little functions that take a floating-point argument representing a timing parameter, calculate an integer value, stuff that value in a peripheral register, then return the true timing value as calculated from the integer. Because keeping track of quantization errors is important.
The fool compiler, however, sees an opportunity to give me a "better" answer with less calculation, and does the final calculation of the return value based on the earlier floating-point calculation. Which doesn't help in the least.
Guess I need to call trunc or maybe round before assigning the result of the first calculation to the integer.
Which, when I try it... fixes one of the functions. The other is still returning the requested value instead of the quantized reality.
Update: The place where adding a call to round didn't fix it? Turns out I was printing the wrong value. D'OH!
Still. Assigning a float value to an int, then casting the int variable's value back to a float and calculating further, should lose the fraction, no?