Division by zero doesn't raise exception in the integer case.

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.
Chuck

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.
It is deliberate. Numarray introduced it (the only difference being that by default NumPy has division-by-zero erros turned off). It's tied to the way floating-point division-by zero is handled. There is a valid argument for having a separate integer-division flag so that you can raise exceptions for integer-division but not for floating-point division. I'm open to that change for 1.0rc1
-Travis

Travis Oliphant wrote:
In [77]: arange(5, dtype=int)/0 Out[77]: array([0, 0, 0, 0, 0])
It is deliberate. Numarray introduced it (the only difference being that by default NumPy has division-by-zero erros turned off). It's tied to the way floating-point division-by zero is handled. There is a valid argument for having a separate integer-division flag so that you can raise exceptions for integer-division but not for floating-point division. I'm open to that change for 1.0rc1
+1 (+inf)
There is a BIG difference between getting an inf with a floating point computation and getting a 0 with an integer one!
Also, the default integer-division flag should be set to raise an exception.
It sure would be nice to have special values for integers too....
Travis Oliphant wrote:
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.
Darn. Oh well.
-Chris

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
participants (3)
-
Charles R Harris
-
Christopher Barker
-
Travis Oliphant