Python can't divide??!?!

Dan Williams dan at ithium.net
Thu Feb 5 12:44:55 EST 2004


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