Python can't divide??!?!
Stephen Boulet
stephendotboulet at motorola_._com
Thu Feb 5 14:05:29 EST 2004
Works fine here:
>>> a = 3/5
>>> b = 3/5.0
>>> c = 3.0/3
>>> d = 3.0/5.0
>>>
>>> print "%f %f %f %f" % (a,b,c,d)
0.000000 0.600000 1.000000 0.600000
but
>>> print "%.17f %.17f %.17f %.17f" % (a,b,c,d)
0.00000000000000000 0.59999999999999998 1.00000000000000000
0.59999999999999998
;)
Stephen
Dan Williams wrote:
> Ummmm...
>
> This is weird. Sorry if it's known about (how can it NOT be, I wonder?) but
> I haven't seen any reference to it anywhere.
>
> I'm running the latest Python (2.3.3) on Windows XP Pro, i386 architecture.
>
> Fire up python or whatever.
>
> Do this: Result:
>
> 3 / 5 0 Fair enough, int / int = int
> 3 / 5.0 0.59999999999999998 eh?
> 3.0 / 3 0.59999999999999998 ummmm...
> 3.0 / 5.0 0.59999999999999998 how did I guess...
>
> That's just an example. Python cannot divide. Period. If you try 1.0 / 3 you
> get 0.33333333333333331, and from this, the above example, and a few tests,
> I speculate that *something* is subtracting 2 from the last digit *after*
> the division is done.
>
> Wacky.
>
> Now, is this just me, or can someone else duplicate it? I've tried it on two
> computers here, but they're both Win XP. I'm about to test it on Linux but I
> figured I'd write this first.
>
> Dan
>
>
>
More information about the Python-list
mailing list