[issue22198] Odd floor-division corner case

Mark Dickinson report at bugs.python.org
Thu Aug 14 21:42:08 CEST 2014


Mark Dickinson added the comment:

Steven: there's a set of (unwritten) rules for how the IEEE 754 operations work.  (I think they actually *were* articulated explicitly in some of the 754r drafts, but didn't make it into the final version.)  One of them is that ideally, a floating-point operations works as though the corresponding mathematical operation were performed exactly on the inputs (considered as real numbers), followed by a rounding step that takes the resulting real number and rounds it to the nearest floating-point number.  This is how essentially *all* the operations prescribed in IEEE 754 behave, with a greater or lesser amount of hand-waving when it comes to specifying results for special cases like infinities and nans.  In this case, the underlying mathematical operation is `x, y -> floor(x / y)`.  The only tricky point is the extension to infinity, but we've got the existing behaviour of regular division to guide us there - the result of dividing a finite value by an infinity is an appropriately signed zero.  So there's really not a lot of room for manoeuvre in an IEEE 754-like operation.

> The alternative is a discontinuity, where -0.5//x = -1 for all finite 
> but huge x and then suddenly 0 when x overflows to infinity. That's 
> probably a bad idea.

Shrug: the underlying mathematical operation is discontinuous; I really don't see a problem here.  In any case, if you're worried about discontinuities, what about the one that occurs between positive values and negative values of x in the current implementation (a jump from 0 to -1)?  Continuity takes second place to correctness here.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22198>
_______________________________________


More information about the Python-bugs-list mailing list