Python is letting me down...

May 02, 2009 18:22

I'm running Python 2.6.2 in Ubuntu 9.04 and I'm beginning to get the impression that someone hates me. Run this script if you can. I think it's pretty self explanatory. Python insists that 10*(1-0.9) is not equal to 1.0. The difference between 10*(1-0.9) and 1.0 is ~2.2204e-16. I can't use floor, because I actually don't want 1+2.2204e-16 (or any other fraction plus one) to be equal to 1.0.

x = -0.9
y = 10*(x+1)

if(y != 1.0):
    print y,'!=',1.0
    print y,'- 1.0 =',y-1.0
else:
    print 'I hate you.'
       
Previous post Next post
Up