Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))`
cool-RR
ram.rachum at gmail.com
Wed Sep 17 17:16:03 CEST 2014
On Wednesday, September 17, 2014 6:10:35 PM UTC+3, Chris Angelico wrote:
> 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.
Despite the fact it goes up in jump, it still satisfies the mathematical condition needed for a limit. (I won't quote the epsilon-delta thing but I think you can find it.)
> 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.
I didn't ask for the modulo, I agree it should remain NaN. I'm talking about the floor division. I don't see any problems this will cause with primality. "I'm not sure that that would really help anything" is a little bit too vague.
Thanks,
Ram.
More information about the Python-list
mailing list