[Python-ideas] Fwd: Make `float('inf') //1 == float('inf')`

Ian Cordasco graffatcolmingov at gmail.com
Wed Sep 17 23:52:05 CEST 2014


---------- Forwarded message ----------
From: Ian Cordasco <graffatcolmingov at gmail.com>
Date: Wed, Sep 17, 2014 at 4:51 PM
Subject: Re: [Python-ideas] Make `float('inf') //1 == float('inf')`
To: Ram Rachum <ram.rachum at gmail.com>
Cc: "python-ideas at googlegroups.com" <python-ideas at googlegroups.com>


On Wed, Sep 17, 2014 at 11:42 AM, Ram Rachum <ram.rachum at gmail.com> wrote:
> Please see this discussion on python-list:
>
> https://groups.google.com/forum/#!topic/comp.lang.python/maDZoc-n4bA
>
> Currently `float('inf') //1` is equal to NaN. I think that this is really
> weird. If I understand correctly it's to maintain the invariant `div*y + mod
> == x`. The question is, do we really care more about maintaining this
> invariant rather than providing a mathematically reasonable value for floor
> division?

Actually there are 2 things here:

1. Mathematically speaking, infinity is a real number and modulo
arithmetic is algebraically not defined for it. So the "mathematically
reasonable value" is NaN. Is it intuitive for someone who hasn't
studied abstract algebra? Probably not. Is it functional for the
scientific python community? Almost certainly although I won't pretend
to speak on their behalf

2. Changing this behaviour is not something I think we should do in a
minor version of 3.4 or in 3.5 (or really 3.x).


More information about the Python-ideas mailing list