[Numpy-discussion] Oddity with numpy.int64 integer division

Timothy Hochberg tim.hochberg@ieee....
Tue Apr 24 16:33:52 CDT 2007


On 4/24/07, Robert Kern <robert.kern@gmail.com> wrote:
>
> Christian Marquardt wrote:



> > Restore the invariant, and follow python.


This seems to imply that once upon a time numpy/numeric/numarray followed
python here, but as far as I can recall that was never the case. Instead
they followed C completely, ostensibly for performance reasons. That
preserved the invariant in question, but not compatibility with Python.


>
> > This
> >
> >    >>> -5 // 6
> >    -1
> >
> > and
> >
> >    >>> array([-5])[0] // 6
> >    0
> >
> > simply doesn't make sense - in any language, you would expect that
> > all basic operators provide you with the same same answer when
> > applied to the same number, no?
>
> Not if they are different types, you don't, e.g. -5.0 / 6 .


That's perhaps not the best example since this difference is slated for
removal someday:

>>> from __future__ import division
>>> -5/6
-0.83333333333333337
>>> -5.0/6.0
-0.83333333333333337

Personally I'd opt for completely following Python here, with the C-like
integer division and mod operators available as appropriately named ufuncs
somewhere. It's a backwards incompatible change though, so it'd have to wait
till at least a minor realease.



-- 

//=][=\\

tim.hochberg@ieee.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20070424/403fbc4d/attachment.html 


More information about the Numpy-discussion mailing list