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


Groups > comp.lang.python > #28695

Re: Division help in python

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeder2.ecngs.de!ecngs!feeder.ecngs.de!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <prvs=5903110a8=jeanmichel@sequans.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'subject:help': 0.07; 'python': 0.09; 'integer,': 0.09; 'negative,': 0.09; 'cc:addr:python-list': 0.10; 'subject:python': 0.11; 'division,': 0.16; 'prefered': 0.16; 'stuff.': 0.16; 'uniqueness': 0.16; 'wrote:': 0.17; 'yield': 0.17; 'solution.': 0.18; '>>>': 0.18; 'all,': 0.21; 'cheers,': 0.23; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'second': 0.24; 'so.': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'url:wiki': 0.26; 'checking': 0.27; 'division': 0.29; 'url:wikipedia': 0.29; 'definition': 0.29; 'probably': 0.29; 'basic': 0.30; 'strict': 0.33; 'problem': 0.33; 'problem,': 0.35; 'doing': 0.35; 'but': 0.36; 'url:org': 0.36; 'should': 0.36; 'being': 0.37; 'why': 0.37; 'subject:: ': 0.38; 'positive': 0.38; 'mean': 0.38; 'url:en': 0.38; 'instead': 0.39; 'received:194': 0.61; 'kindly': 0.67; 'brand': 0.78; '1st': 0.81; 'valid,': 0.84
X-IronPort-AV E=Sophos;i="4.80,387,1344204000"; d="scan'208";a="709511"
X-Virus-Scanned amavisd-new at zimbra.sequans.com
Date Fri, 07 Sep 2012 18:19:17 +0200
From Jean-Michel Pichavant <jeanmichel@sequans.com>
User-Agent Mozilla-Thunderbird 2.0.0.24 (X11/20100328)
MIME-Version 1.0
To Ramyasri Dodla <ramyasri20@gmail.com>
Subject Re: Division help in python
References <CAB2OTpf290sL8kncrVADr-YD1hvUP=R424C8xd+BGGivF5AdhA@mail.gmail.com>
In-Reply-To <CAB2OTpf290sL8kncrVADr-YD1hvUP=R424C8xd+BGGivF5AdhA@mail.gmail.com>
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 8bit
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.360.1347034758.27098.python-list@python.org> (permalink)
Lines 42
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1347034758 news.xs4all.nl 6927 [2001:888:2000:d::a6]:39983
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:28695

Show key headers only | View raw


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


Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web