It's not exactly with 1 > 1 but close:
I want to compare two timestamps and do something if time > timestamp
evaluates to True
.
Both variables have the same float
in them, as seen in pdb
(Pdb) print time
1396836917.98
(Pdb) print last_timestamp
1396836917.98
(Pdb) if time > last_timestamp: print 'wtf'
wtf
I would expect this to evaluate as False
, it seems to be a float
problem:
(Pdb) if float(time) > float(last_timestamp): print 'wtf'
wtf
int
comparison works fine
(Pdb) if int(time) > int(last_timestamp): print 'wtf'
So I expected a problem with the precision of available bits representing the number
(Pdb) if float(time)*100 > float(last_timestamp)*100: print 'wtf'
wtf
but it still evaluates as True
if there are no decimal places left ..
A work around for me right now is
if int(time*100) > int(last_timestamp*100): print 'wtf'
but I'd really love to understand what is going on and how to use the >
operator correctly with float
..