numpy/numpy — pull request #3199 by ivanov (2013-04-06 03:19:16+00:00)
Title: documentation, tests, and bugs in seterr behavior for integer types

this is a work in progress. it started off as a documentation improvement for the fact, currently captured in #593 that `np.seterr` does not affect error handling behavior for arrays of integers (although it does mostly work for integer scalars).

But in writing a test for this behavior (which I was intending to submit and mark as a KnownFailure), I discovered two other bugs in the scalar handling. These examples assume that `np.seterr(all='raise')` has already been called.

1. Integer scalar underflow (for all int types) is reported as overflow. Here's a bit of misinformation - should be UNDER-flow, not overflow
```
In [28]: np.int8(-128) - np.int8(1)
---------------------------------------------------------------------------
FloatingPointError Traceback (most recent call last)
in ()
----> 1 np.int8(-128) - np.int8(1)

FloatingPointError: overflow encountered in byte_scalars
```
2. int64 overflow is ignored during multiplication
```
In [14]: d = np.int8; i = np.iinfo(d); d(i.max) * d(2)
---------------------------------------------------------------------------
FloatingPointError Traceback (most recent call last)
in ()
----> 1 d = np.int8; i = np.iinfo(d); d(i.max) * d(2)

FloatingPointError: overflow encountered in byte_scalars

Good, we also get errors for int16, int32, but not int64
```
In [17]: d = np.int64; i = np.iinfo(d); d(i.max) * d(2)
Out[17]: -2
```