Steven D'Aprano <steve+pyt...@pearwood.info> added the comment:
Although it often gets called "integer division", that's not actually what // does, it is actually *floor* division, as documented here: https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex So the behaviour as given is correct: it returns the floor of the quotient. Arguments are coerced to a common type in the normal fashion, so float//int performs the floor division in floating point, which may not give the same result as integer floor division due to floating point rounding: py> 10**17 // 7 14285714285714285 py> 1e17 // 7 1.4285714285714284e+16 If you don't want floating point rounding, don't use floats. If you want "true division", use / not the floor division operator. This isn't a bug, it is working as designed. Even if the behaviour you are asking for was possible, practical and desirable, it would break backwards compatibility. There's no way to do a "floor division that returns an int" for all float arguments, since there are no int NANs. py> float('inf')//7 nan ---------- nosy: +steven.daprano resolution: -> not a bug stage: -> resolved status: open -> closed _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue38929> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com