# [Numpy-discussion] Binary ufuncs: minimum

Charles R Harris charlesr.harris@gmail....
Tue May 27 22:23:16 CDT 2008

```On Tue, May 27, 2008 at 8:14 PM, Keith Goodman <kwgoodman@gmail.com> wrote:

> On Tue, May 27, 2008 at 4:27 PM, Nathan Bell <wnbell@gmail.com> wrote:
> > On Tue, May 27, 2008 at 5:39 PM, Christopher Barker
> > <Chris.Barker@noaa.gov> wrote:
> >>
> >> I'm not so sure. I know I wouldn't expect to get a different type back
> >> with a call to abs(). Do we really want to change that expectation just
> >> for the case of MIN_INT?
> >>
> >> While everyone is going to want an unsigned value when calling abs(),
> >> who knows if they might want to use negative numbers later? Like:
> >>
> >> x = abs(x)
> >> x *= -1
> >>
> >> Now what do we get/want?
> >
> > IMO abs() returning non-negative numbers is a more fundamental
> > property.  In-place operations on integer arrays are somewhat
> > dangerous, and best left to more sophisticated users anyway.
> >
> >
> > Interestingly, MATLAB (v7.5.0) takes a different approach:
> >
> >>> A = int8([ -128, 1])
> > A =
> >  -128    1
> >>> abs(A)
> > ans =
> >  127    1
> >>> -A
> > ans =
> >  127   -1
>
> octave-3.0.1:1> A = int8([-128,1])
> A =
>  -128  1
> octave-3.0.1:2> abs(A)
> ans =
>   128     1
> octave-3.0.1:3> -A
> ans =
>   127    -1
> ______
>

We could simply define the range of int8 as [-127,127], but that is somewhat
problematical also. It is probably important to distinguish between the
hardware and mathematical correctness, not that we are ever going to
represent all the integers in a finite number of bits.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080527/eb91f458/attachment.html
```