[Numpy-discussion] abs for max negative integers - desired behavior?
Tue Oct 11 14:36:23 CDT 2011
On Tue, Oct 11, 2011 at 3:16 PM, Charles R Harris
> On Tue, Oct 11, 2011 at 12:23 PM, Matthew Brett <firstname.lastname@example.org>
>> I recently ran into this:
>> In : arr = np.array(-128, np.int8)
>> In : arr
>> Out: array(-128, dtype=int8)
>> In : np.abs(arr)
>> Out: -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.
Ah - sorry - I think I missed the previous discussion.
The conversion to unsigned seemed like an great improvement. Are you
saying that the cost down the line is an increase in memory use for
arrays which are then combined with a signed type? That seems like a
reasonable trade-off to me. Was that the main objection?
More information about the NumPy-Discussion