Posted: Sun Jul 10, 2011 9:38 am Post subject: Single variable, different value between input and output ?
Hi all,
I am sorry if my question has ever be asked.
I have input value with single variable and then saving to eeprom, but after I print this variable or read it from eeprom, this value is different with input value.
first of all you use a very old version. but for the problem this does not matter.
you need to read the help topic about SINGLE variables.
Essential, you can not store every number exactly into a single. So the problem will be when you read it or print it.
Some values can be stored exactly, like 0.0 but most number with fractions not.
Use a double for more precision, or a long and scale it.
This is a problem related to single precision numbers.
if you try this on your calculator : 1/3 and you mul by 3 the result will not be 1 either. _________________ Mark
Thank you for your advice.
I already try with double variable and it's OK for small code.
But when I try at my huge code which achieves 70% capacity of Atmega32, then error message appears after compiled:
"Error 220: Line: 1730 Forward jump out of range [_STR2BYTE] ...."
Line: 1730 points to end of code line, it means it does not point to specific code so I don't know which code is problem.
Do you know what problem is ?
Also another snippet code:
B = 2 + Int(A)
If A and B are Single, this code is OK, but if A and B are Double, the code will be error so it has to be changed to 2 code lines:
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum