[Numpy-discussion] Weird clipping when astype(int) used on large numbers

2008-10-17 Thread Tony S Yu
I ran into this weird behavior with astype(int) In [57]: a = np.array(1E13) In [58]: a.astype(int) Out[58]: array(-2147483648) I understand why large numbers need to be clipped when converting to int (although I would have expected some sort of warning), but I'm puzzled by the negative

Re: [Numpy-discussion] Weird clipping when astype(int) used on large numbers

2008-10-17 Thread Matthieu Brucher
Hi, This a usual thing in integers conversions. If you transform an integer like 0x from 16 bits to 8bits, you get 0x, thus a negative number. As there are no processor instructions that do saturations (DSP instructions), the behavior is to be expected. Matthieu 2008/10/17 Tony S Yu

Re: [Numpy-discussion] Weird clipping when astype(int) used on large numbers

2008-10-17 Thread Charles R Harris
On Fri, Oct 17, 2008 at 1:27 PM, Tony S Yu [EMAIL PROTECTED] wrote: I ran into this weird behavior with astype(int) In [57]: a = np.array(1E13) In [58]: a.astype(int) Out[58]: array(-2147483648) I understand why large numbers need to be clipped when converting to int (although I would