[Numpy-discussion] float('inf') // 1 = ?
Sebastian Berg
sebastian at sipsolutions.net
Thu Sep 18 14:41:49 EDT 2014
On Do, 2014-09-18 at 19:13 +0200, Sebastian Berg wrote:
> On Thu, 2014-09-18 at 18:55 +0200, Petr Viktorin wrote:
> > Sorry for the lack of subject before.
> >
> > On Thu, Sep 18, 2014 at 6:48 PM, Benjamin Root <ben.root at ou.edu> wrote:
> > > My vote is that NumPy is correct here. I see no reason why
> > >>>> float('inf') / 1
> > > and
> > >>>> float('inf') // 1
> > >
>
> Didn't read python ideas I have to admit (at least not enough to see
> many arguments). My biggest argument is that numpy does exactly this:
>
> >>> import math
> >>> math.floor(float('inf')/1)
>
> Maybe I am naive thinking that floordivide is basically a divide+floor
> operation, but arguing for NaN seems half arsed to me on first sight.
> Either it is `inf` and the equivalence Benjamin Root noted holds or you
> make it an error. NaN is not reasonable for an error return *especially*
> not for the standard lib (it *might* be for numpy).
>
Ok, sorry, that was too quick. Since we already have a "special" value
like Inf, it is OK to not give an error in the standard lib, since
Inf-Inf is also NaN, etc.
However, I read the arguments as "Inf is not an integral number", and I
frankly don't understand that at all. Infinity isn't a real number as
well!?
If you represent the result as an IEEE float (integral or not) you can
use Inf as a valid result IMO. Arguably all of the limits:
floor(float) -> Inf
float // 1 -> Inf
exist for float -> Inf and can be represented. Also IEEE seems to define
the floor operation like this and I don't see a reason why to violate
`a//b == floor(a/b)`. As long as the result is represented as an IEEE
floating point, which knows Infinity, I argue that it is correct. If it
is not an IEEE floating point, it is an error in any case.
- Sebastian
> - Sebastian
>
> > > should return different results.
> >
> > I recommend reading the python-ideas thread; there are some arguments
> > for both sides.
> >
> > > On Thu, Sep 18, 2014 at 12:31 PM, Petr Viktorin <encukou at gmail.com> wrote:
> > >>
> > >> Hello,
> > >> Over at Python-ideas, there is a thread [0] about the following
> > >> discrepancy:
> > >>
> > >> >>> numpy.array(float('inf')) // 1
> > >> inf
> > >> >>> float('inf') // 1
> > >> nan
> > >>
> > >> There are reasons for either result, but I believe it would be very
> > >> nice if either Python or Numpy changed, so they would give the same
> > >> value.
> > >> If any of you have reasons to defend Numpy's (or Python's) choice, or
> > >> otherwise want to chime in, please post there.
> > >>
> > >> Thanks,
> > >> Petr Viktorin
> > >>
> > >>
> > >> [0]
> > >> https://mail.python.org/pipermail/python-ideas/2014-September/029365.html
> > >> _______________________________________________
> > >> NumPy-Discussion mailing list
> > >> NumPy-Discussion at scipy.org
> > >> http://mail.scipy.org/mailman/listinfo/numpy-discussion
> > >
> > >
> > >
> > > _______________________________________________
> > > NumPy-Discussion mailing list
> > > NumPy-Discussion at scipy.org
> > > http://mail.scipy.org/mailman/listinfo/numpy-discussion
> > >
> > _______________________________________________
> > NumPy-Discussion mailing list
> > NumPy-Discussion at scipy.org
> > http://mail.scipy.org/mailman/listinfo/numpy-discussion
> >
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20140918/8e421e30/attachment.sig>
More information about the NumPy-Discussion
mailing list