<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jul 3, 2019 at 11:39 AM Matthew Brett <<a href="mailto:matthew.brett@gmail.com">matthew.brett@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
On Wed, Jul 3, 2019 at 9:08 AM Charles R Harris<br>
<<a href="mailto:charlesr.harris@gmail.com" target="_blank">charlesr.harris@gmail.com</a>> wrote:<br>
><br>
><br>
><br>
> On Wed, Jul 3, 2019 at 9:08 AM Hameer Abbasi <<a href="mailto:einstein.edison@gmail.com" target="_blank">einstein.edison@gmail.com</a>> wrote:<br>
>><br>
>> Hi,<br>
>><br>
>> It turns out you're running into a bit-error. In general, the two's complement of -2 ** (n-1) with the bit-length being limited to n bits is itself... No way around that. And integers don't set hardware exceptions so checking for errors like these is hard as well.<br>
>><br>
>> TL;DR: It's an error with how the integer is stored in memory and how you're running out of space.<br>
>><br>
>> Regards,<br>
>> Hameer Abbasi<br>
><br>
><br>
> More like the eight bit twos complement of -128 is -128, bytes cannot represent 128. Matlab used to (still does?) solve this problem by returning 127 instead :) Basically, the data needs more precision. Returning an unsigned type would lead to it's own problems with unexpected promotions when the result was used. We could, I suppose, raise a warning, although that might be considered noisy. If you use `absolute` instead, you can specify the dtype.<br>
<br>
I still think this is a major wart in numpy's abs.<br>
<br>
I'd really like to add a new function, `uabs` which would return an<br>
unsigned int for integer inputs.  I'm happy to do a pull request if<br>
that also seems sensible to y'all,<br>
<br></blockquote><div><br></div><div>Seems reasonable, it would provide something for discussion. Note that the current abs is in the slot provided by Python numeric types. The main problem is that as soon as the unsigned result is combined with a signed type it will get promoted. Which would not be much of a problem except int64 -> double.</div><div><br></div><div>Chuck</div></div></div>