[Tutor] / vs //

Christopher Smith csmith@blakeschool.org
Wed, 20 Feb 2002 12:47:13 -0600


The two operations below yield different results...does / know something
that // doesn't know? 

>>> 3.9//1.3
2.0
>>> 3.9/1.3
3.0

It seems like // is being technically corrrect since 3.9 is a little
smaller than 3.9 but that / is being a little smarter and trying to give
you a closer approximation. 

>>> 3.9
3.8999999999999999
>>> 1.3
1.3

PEP 238 says that a//b should act like floor(a/b) but you can see in this
example that it doesn't since that result is 3.0 not 2.0

>>> math.floor(3.9/1.3)
3.0



/c