On Apr 23, 2007, at 21:35 , David M. Cooke wrote:

Python defines x // y as returning the floor of the division, and x % y has the same sign as y. However, in C89, it is implementation- defined (i.e., portability-pain-in-the-ass) whether the floor or ceil is used when the signs of x and y differ. In C99, the result should be truncated. From the C99 spec, sec. 6.5.5, #6:
       When integers are divided, the result of the / operator
       is   the   algebraic   quotient  with  any  fractional  part
       discarded.76)  If the quotient  a/b  is  representable,  the
       expression (a/b)*b + a%b shall equal a.

Numpy follows whatever the C compiler decides to use, because of speed-vs.-Python compatibility tradeoff.

Just a followup note: gcc (4.0 and 4.2, at least) with -std=c99 *doesn't* respect this; it still does the platform way (on my MacBook Core Duo, that's truncation towards zero). The assembly it generates is identical for gcc -std=c99 and gcc -std=c89

--
|>|\/|<
/------------------------------------------------------------------\
|David M. Cooke              http://arbutus.physics.mcmaster.ca/dmc/
|[EMAIL PROTECTED]

Attachment: PGP.sig
Description: This is a digitally signed message part

_______________________________________________
Numpy-discussion mailing list
[email protected]
http://projects.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to