I was playing around with os.utime() in Python, and have encountered a curiosity: If I read the mtime (last modified time) from a file, update the file with the same value I've read, and re-read the value, I get different values, as demonstrated here:
#!/usr/bin/python
import os
FN = "tmp_file.txt"
with open(FN, 'w') as the_file:
the_file.write("hello\n")
t1 = os.path.getmtime(FN)
os.utime(FN, (t1, t1))
t2 = os.path.getmtime(FN)
print "mtime before: %.10f" % t1
print "mtime after: %.10f" % t2
print t1 == t2
print t2 - t1
If I run this, output looks like:
mtime before: 1502410779.6215209961
mtime after: 1502410779.6215200424
False
-9.53674316406e-07
But it's not completely random. It looks like there are maybe ~5 possible outcomes, including perfect equality.
I would think this is just a straight-up "write" as-is, so I don't expect floating point arithmetic to mess things up. What's happening here?