Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))`
rosuav at gmail.com
Wed Sep 17 17:10:14 CEST 2014
On Thu, Sep 18, 2014 at 12:55 AM, cool-RR <ram.rachum at gmail.com> wrote:
> Terry, that doesn't really answer the question "why", it just pushes it back to the documentation. Is there a real answer why? Why return NaN when Inf would make mathematical sense?
To answer that, we have to first look at what it means to do
operations on Inf. The definition of "Infinity + 1" is the limit of "x
+ 1" as x goes toward positive infinity - which is positive infinity.
Same with infinity-1, infinity/1, infinity*1, etc, etc, etc. So far,
so good. But as x tends toward positive infinity, the value of "x //
1" (or simply of floor(x)) doesn't simply increase tidily. It goes up
in little jumps, every time x reaches a new integer. And while it's
conceivable to define that infinity divided by anything is infinity,
and infinity modulo anything is zero, that raises serious issues of
primality and such; I'm not sure that that would really help anything.
So there's no possible value for floor division of infinity, ergo the
result is NaN.
So. There you have an answer. Now, for your next question, can you
please use something better than Google Groups, or at least learn how
to use an interleaved posting style and trim out all the excess blank
More information about the Python-list