I have some code that generates random numbers on the Arduino, it then sends these random numbers firstly, using
Serial.print(float data,int lenght) and as a floating point number using the following function
void send_float (float arg)
// get access to the float as a byte-array:
byte * data = (byte *) &arg;
// write the data to the serial
Serial.write (data, sizeof (arg));
I then receive this data using python, take the absolute difference of the two values, discard any differences less than the length with which I send the string and output the rest to the screen.
I observe two things, a) Fluctuations of the order with which I send the data (ie. if I send to 6 decimal places then I see fluctuations of ~1e-6), this is reasonable and b) I see fluctuations of absolute value 1e-8 or lower independent of what accuracy I send the string.
Even if I send the string to 11 decimal places, when I compare against the float I see fluctuations up to but not above 1e-8.
Why? This doesn't make any sense. My full code is actually the answer to an old unanswered stack exchange question