[Numpy-discussion] Division by zero doesn't raise exception in the integer case.

Travis Oliphant oliphant at ee.byu.edu
Tue Sep 19 18:53:32 CDT 2006


Charles R Harris wrote:

> Travis,
>
> Is this intentional?
>
> In [77]: arange(5, dtype=int)/0
> Out[77]: array([0, 0, 0, 0, 0])
>
> It looks deliberate because all zeros are returned, but it might be 
> better if it raised an exception.


As mentioned before we translate integer division errors into 
floating-point erros and use the same hardware trapping to trap them if 
the user requests it.     Simulating and "integer-division-by-zero" 
hardware flag is not trivial as we would have to manage context 
switching ourselves.   So, at least for 1.0, integer and floating-point 
division by zero are going to be handled the same.

-Travis





More information about the Numpy-discussion mailing list