The fact that var 22.6 and constant 22.6 are converted to different floats seems odd, considering neither var nor constant form have any ambiguity with this many digits. Also, since neither var nor other forms of fixed-point math are native to C, "one of the first things to learn in C courses" is not intuitively applicable. It's also not a reasonable expectation to have of anyone here, since this is the Lite-C forum, and not only are they different, but the Lite-C documentation is usually sufficient for Lite-C. Whether or not someone's a beginner in that context has nothing to do with this question.
Originally Posted By: Petra
The var 22.6 is always slightly less than the float 22.6 because some decimals are cut off.
While in a general sense you are correct about the problem, this sentence appears incorrect to me. As 22.6 fits well within the precision of a var, and with this small a number a float has much more precision than a var, no decimal places are being cut off. Rather, they're being approximated differently. Again, I find that peculiar, but I guess there's a good reason for it -- perhaps an on-the-fly conversion is sloppily done while a conversion performed during compilation can take more time and is thus performed differently. I'd love a knowledgeable explanation, minus the patronising, please.

Finally, @jcl:

As fun as it is to play "Who can figure out this guy's problem?", I think this is either a "blame the manual" situation or a bug, and does not belong in this forum. The documentation doesn't address this issue appropriately -- where it says that constants with decimal points are treated as floats, it also says that floats are reliably accurate to about 6 decimal places, so preparation for this issue is not a reasonable expectation for any Lite-C programmer.
-- retracted. The manual is clear in "Comparisons" about not using the equivalence test for any non-integer variables, and while this isn't done directly, it's reasonable to say it's the same issue.

Last edited by JibbSmart; 01/15/12 02:48.

Formerly known as JulzMighty.
I made KarBOOM!