On Thu, Sep 18, 2014 at 5:20 PM, Ian Cordasco firstname.lastname@example.org wrote:
On Thu, Sep 18, 2014 at 9:09 AM, Petr Viktorin email@example.com wrote:
On Thu, Sep 18, 2014 at 3:38 PM, Ian Cordasco firstname.lastname@example.org wrote:
On Sep 18, 2014 2:31 AM, "Petr Viktorin" email@example.com wrote:
For the record, this gives inf in Numpy.
> import numpy > numpy.array(float('inf')) // 1
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.
Sorry? If you've studied mathematics you'd know there's no discrete value that is the same as infinity. I'm not even sure how anyone could begin define floor(infinity). Infinity is not present in any discrete set. Yes float('inf') / 1 should be float('inf'), no one is arguing that. That's easily shown through limits. floor(float('inf') / 1) has no intrinsic meaning. Discrete sets such as the naturals, integers, and rationals are all "countably infinite" but there's no bijective mapping between them and the real numbers (and therefore, no such mapping to the complex numbers) because the are uncountably infinite real numbers.
There is even no *real* number that is the same as infinity. The result of // on floats is a float; discrete sets don't come into play. Practically, floor(f) is f minus a value between 0 and 1. If you have (x1 = y1 // a) and (x2 = y2 // a) and (y1 < y2 - a), then (x1 < x2); as y grows without bound, x will also grow without bound. Correct me if I'm wrong, I did study math but it is rusty.
I understand that intuitively float('inf') // 1 being equal to infinity is nice, but it is inherently undefined. We don't really have the concept of undefined so NaN seems most acceptable.
I disagree with is the conclusion that NaN is the most appropriate. But the discussion is starting to go in circles here, and I actually don't much care for the actual result.
Are any Numpy developers around? Is there a reason it has different behavior from Python?
I expect because of np.array semantics it is different. I'm not sure if it's intentional or if it's a bug, but I'm curious as well.
What I do care about is that Python and Numpy should give the same result. It would be nice to see this changed in either Python or Numpy, whatever the "correct" result is.