Re: Integer dicision

2008-04-17 Thread Mark Wooding
bdsatish <[EMAIL PROTECTED]> wrote: > How does (a/b) work when both 'a' and 'b' are pure integers ? > >>> (9/2) > 4 > >>> (-9/2) > -5 > > Why is it -5 ? I expect it to be -4 ? Because, in C/C++, 9/2 is 4 and > so negative of it, (-9/2) is -4. Some background on the situation: Integer division and

Re: Integer dicision

2008-04-11 Thread Paul Hankin
On Apr 11, 6:06 am, casevh <[EMAIL PROTECTED]> wrote: > On Apr 10, 9:28 pm, bdsatish <[EMAIL PROTECTED]> wrote: > > > How does (a/b) work when both 'a' and 'b' are pure integers ? > > Python defines the quotient and remainder from integer division so > that a = qb + r and 0<=r < abs(b). C/C++ lets

Re: Integer dicision

2008-04-10 Thread casevh
On Apr 10, 9:28 pm, bdsatish <[EMAIL PROTECTED]> wrote: > How does (a/b) work when both 'a' and 'b' are pure integers ? Python defines the quotient and remainder from integer division so that a = qb + r and 0<=r < abs(b). C/C++ lets the remainder be negative. >>> divmod(-9,2) (-5, 1) >>> divmod(9

Re: Integer dicision

2008-04-10 Thread jim
it rounds down. 4 is less than 4.5 and -5 is less than -4.5. On Thu, 2008-04-10 at 21:28 -0700, bdsatish wrote: > How does (a/b) work when both 'a' and 'b' are pure integers ? > > >> (9/2) > 4 > > >> (-9/2) > -5 > > Why is it -5 ? I expect it to be -4 ? Because, in C/C++, 9/2 is 4 and > so n

Re: Integer dicision

2008-04-10 Thread Steve Holden
bdsatish wrote: > How does (a/b) work when both 'a' and 'b' are pure integers ? > >>> (9/2) > 4 > >>> (-9/2) > -5 > > Why is it -5 ? I expect it to be -4 ? Because, in C/C++, 9/2 is 4 and > so negative of it, (-9/2) is -4. > > What should I do to get C-like behavior ? Use C? regards Steve -

Integer dicision

2008-04-10 Thread bdsatish
How does (a/b) work when both 'a' and 'b' are pure integers ? >> (9/2) 4 >> (-9/2) -5 Why is it -5 ? I expect it to be -4 ? Because, in C/C++, 9/2 is 4 and so negative of it, (-9/2) is -4. What should I do to get C-like behavior ? -- http://mail.python.org/mailman/listinfo/python-list