Charles R Harris wrote:
>
>
> On Tue, May 27, 2008 at 4:07 PM, Christopher Barker 
> <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> wrote:
>
>     Charles R Harris wrote:
>
>     > Yep, abs fails:
>     >
>     > In [1]: abs(array([-128,-128], dtype=int8))
>     > Out[1]: array([-128, -128], dtype=int8)
>
>     Well, yes, but this is a know vagary of the the hardware
>     implementation
>     for signed integers, as demonstrated by that JAVA Puzzles video
>     that Jon
>     Wright pointed us to a couple days ago. (Which to me could have been
>     titled: "Why I don't want to use JAVA")
>
>     Sure, it could be fixed in this case by promoting to a larger
>     type, but
>     it's going to fail at the largest integer anyway, and I don't
>     think any
>     expects abs() to return a new type.
>
>
> No, it could be completely fixed by promoting the output to the 
> corresponding unsigned type. It wouldn't even require much cleverness 
> in the ufunc.
>
> In [2]: abs(array([-128,-128], dtype=int8)).view(uint8)
> Out[2]: array([128, 128], dtype=uint8)

Cool!  More intersting bit information about 2's complement.

-Travis


_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to