[Numpy-discussion] Re: range/arange

Paulo Jose da Silva e Silva pjssilva at ime.usp.br
Thu Apr 13 05:51:02 EDT 2006


Em Qui, 2006-04-13 às 07:15 -0500, Robert Kern escreveu:

> 
> Python's rule for integer division is to round towards negative infinity. C's
> rule (if it has one; I think it may be platform dependent) is to round towards
> 0. When it comes to arithmetic, numpy tends to expose the C behavior because
> it's fastest. As Lars pointed out, the type of the object that you get from
> iterating over an array is a numpy int32scalar object, so the numpy behavior is
> used.
> 

Actually, in C99 standard the division was defined to truncate towards
zero always, see item 25 in:

http://home.datacomm.ch/t_wolf/tw/c/c9x_changes.html

So it is not platform dependent anymore.

Paulo

Obs: It once was platform dependent. Old gcc (for Linux) would truncate
towards infinity. I know this because of a "bug" in somebody else's
code. I took me a quite some time to discover that the problem was the
shift in gcc behavior in this matter.





More information about the NumPy-Discussion mailing list