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

Petr Viktorin encukou at gmail.com
Thu Sep 18 16:09:26 CEST 2014


On Thu, Sep 18, 2014 at 3:38 PM, Ian Cordasco
<graffatcolmingov at gmail.com> wrote:
>
> On Sep 18, 2014 2:31 AM, "Petr Viktorin" <encukou at gmail.com> wrote:
>>
>> For the record, this gives inf in Numpy.
>>
>> >>> import numpy
>> >>> numpy.array(float('inf')) // 1
>> inf
>>
>> AFAIK this and http://bugs.python.org/issue22198 are the only
>> differences from Python floats, at least on my machine.
>
> That's an interesting bug report and it's significantly different
> (mathematically speaking) from the discussion here. That aside, I have to
> wonder if numpy has its own way of representing infinity and how that
> behaves. I still maintain that it's least surprising for float('inf') // 1
> to be NaN. You're trying to satisfy float('inf') = mod + 1 * y and in this
> case mod and y are both indeterminate (because this is basically a
> nonsensical equation).

Well, in `x = y // a`, as y tends towards infinity, x will also tend
towards infinity, though in discrete steps. Yes, you get an
indeterminate value, but one that's larger than any real number.


Are any Numpy developers around? Is there a reason it has different
behavior from Python?


More information about the Python-ideas mailing list