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 divisionbyzero erros turned off). It's tied to the way floatingpoint divisionby zero is handled. There is a valid argument for having a separate integerdivision flag so that you can raise exceptions for integerdivision but not for floatingpoint 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 divisionbyzero erros turned off). It's tied to the way floatingpoint divisionby zero is handled. There is a valid argument for having a separate integerdivision flag so that you can raise exceptions for integerdivision but not for floatingpoint 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 integerdivision 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 "integerdivisionbyzero" hardware flag is not trivial as we would have to manage context switching ourselves. So, at least for 1.0, integer and floatingpoint 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 floatingpoint erros and use the same hardware trapping to trap them if the user requests it. Simulating and "integerdivisionbyzero" hardware flag is not trivial as we would have to manage context switching ourselves. So, at least for 1.0, integer and floatingpoint division by zero are going to be handled the same.
Travis
participants (3)

Charles R Harris

Christopher Barker

Travis Oliphant