2012-05-10 04:01 AM
Dear all,
I have some strange roundings with float values: for example when I write 0.05 in eeprom (calibration parameters) it becomes 0.049999997 when I read It.0.2 becomes 0,199999988.I use Cosmic compiler, I tried to change FLT_DIG in float.h but nothing changes.If someone has a clue please help me.Many thanks in advance #floating-point---just-say-no #stm8-stm8l-float-rounding-cosmic2012-05-10 07:36 AM
Neither 0.2 nor 0.05 can be represented exactly in floating point format. Google IEE754 and check out the Wikipedia entries for both the 1985 & 2008 versions of the standard. Those should give you a good idea of what you're seeing.
jdf2012-05-10 07:37 AM
ooops
I meant IEEE754 (3 E's) jdf2012-05-12 10:58 AM
As already noted, this is an inherent artifact of floating-point.
Another reason to avoid floating-point unless you really, really have a very specific need for it...2012-06-12 07:34 AM