[Numpy-discussion] abs for max negative integers - desired behavior?
Benjamin Root
ben.root@ou....
Tue Oct 11 19:05:51 CDT 2011
On Tue, Oct 11, 2011 at 6:33 PM, <josef.pktd@gmail.com> wrote:
> On Tue, Oct 11, 2011 at 7:13 PM, Benjamin Root <ben.root@ou.edu> wrote:
> > On Tue, Oct 11, 2011 at 2:51 PM, Matthew Brett <matthew.brett@gmail.com>
> > wrote:
> >>
> >> Hi
> >>
> >> On Tue, Oct 11, 2011 at 3:16 PM, Charles R Harris
> >> <charlesr.harris@gmail.com> wrote:
> >> >
> >> >
> >> > On Tue, Oct 11, 2011 at 12:23 PM, Matthew Brett
> >> > <matthew.brett@gmail.com>
> >> > wrote:
> >> >>
> >> >> Hi,
> >> >>
> >> >> I recently ran into this:
> >> >>
> >> >> In [68]: arr = np.array(-128, np.int8)
> >> >>
> >> >> In [69]: arr
> >> >> Out[69]: array(-128, dtype=int8)
> >> >>
> >> >> In [70]: np.abs(arr)
> >> >> Out[70]: -128
> >> >>
> >> >
> >> > This has come up for discussion before, but no consensus was ever
> >> > reached.
> >> > One solution is for abs to return an unsigned type, but then combining
> >> > that
> >> > with signed type of the same number of bits will cause both to be cast
> >> > to
> >> > higher precision. IIRC, matlab was said to return +127 as abs(-128),
> >> > which,
> >> > if true, is quite curious.
> >>
> >> octave-3.2.3:1> a = int8([-128, 127])
> >> a =
> >>
> >> -128 127
> >>
> >> octave-3.2.3:2> abs(a)
> >> ans =
> >>
> >> 127 127
> >>
> >> Matlab is the same. That is curious...
> >>
> >> See you,
> >>
> >> Matthew
> >
> > Well, it _is_ only off by 0.78%. That should be good enough for
> government
> > work, right?
>
> So, which government is using numpy, only off by 200%
>
> Josef
>
>
Not government, but maybe Lockheed-Martin when they were doing that Mars
probe?
"What? It was negative? Well, that explains why it went down, not up!"
::rimshot::
Thank you folks! I will be here all week!
Ben Root
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20111011/661b9174/attachment.html
More information about the NumPy-Discussion
mailing list