Tell me more ×  I came across an issue using Python with
floating point errors. I though it might be useful to mention it
here.  I have an external sampling system that records data at
5000Hz. In order to get timestamps I take the initial time and
then add (1.0/5000) to get the timestamp for successive samples.
I noticed very quickly the current time (time.time()) drifted
away from the calculated time when using a loop. just doing the
simple calculation there was no noticeable drift - Some code:
start_time = time.time() start_time_test = start_time #get 512
samples - takes 512*1.0/5000 seconds for i in arange(512):
start_time = start_time + (1.0/5000) #5khz   start_time_test =
start_time_test + 512*(1.0/5000)  print time.time() -
start_time_test #no drift  print time.time() - start_time #
drifts  print start_time_test - start_time # constant increment
Now the difference between start_time_test and start_time is not
insignificant - It's about 1.69e-5 per block of 512 which very
quickly starts to add up. I