7 comments

[ 3.4 ms ] story [ 34.9 ms ] thread
If it's of any help, "//" is "floor division", not "division".
python, because solving basic number issues is still fun as of 2019
In Lisp, this comes out to 10 with 0 remainder.

    > (floor 4 0.4)
    10
    0.0
Doesn't python return the remainder? It would be interesting to see what happened to give an answer of 9. If it is because of floating point (which is silly when dealing with such low numbers and producing such off-the-wall results) then maybe it is incorrectly getting 9.9999... for the division, and not returning the remaining .9999...
Python doesn't return the remainder from floor division, but that's why the modulo operator was invented:

  >>> 4//0.4
  9.0
  >>> 4%0.4
  0.3999999999999998
It does look to be a problem with float precision.
Oddly, the naive way you'd expect `4 // 0.4` to be implemented:

    >>> math.floor( 4 / 0.4 )
    10
does exactly the right thing.
Definitely. In Lisp, it returns the answer I (and everyone else, I'm guessing) would expect.

    > (mod 4 0.4)
    0.0