Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #28695 > unrolled thread

Re: Division help in python

Started byJean-Michel Pichavant <jeanmichel@sequans.com>
First post2012-09-07 18:19 +0200
Last post2012-09-07 18:19 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Division help in python Jean-Michel Pichavant <jeanmichel@sequans.com> - 2012-09-07 18:19 +0200

#28695 — Re: Division help in python

FromJean-Michel Pichavant <jeanmichel@sequans.com>
Date2012-09-07 18:19 +0200
SubjectRe: Division help in python
Message-ID<mailman.360.1347034758.27098.python-list@python.org>
Ramyasri Dodla wrote:
> Hi All,
>
> I am brand new to python. checking over basic stuff. I came across the 
> problem while doing so. If any body aware of the problem, kindly 
> respond me.
>
> >>> 5/10
> 0
> >>> - 5/10
> -1
>
> The second case also should yield a 'zero' but it is giving a -1
>
Why should it yield 'zero' ?
The definition of the euclidean division : 
(http://en.wikipedia.org/wiki/Euclidean_division)

a = b*q +r with 0≤ r < |b|

With the constraint of r being a positive integer, the couple (q, r) is 
unique:

with a=-5, b=10

-5 = 10*-1 + 5 (q=-1, r=+5)

Note that for the strict Euclidean division, I mean the one allowing r 
to be negative, then

-5 = 10*0 - 5 (q=0, r=-5) is also valid, but I there's still no reason 
to state that it SHOULD be prefered over the other solution.

The uniqueness of the solution for the 1st definition is probably what 
makes python yield -1 instead of 0.

Cheers,

JM


[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web