Re: Division help in python

Discussion in 'Python' started by Jean-Michel Pichavant, Sep 7, 2012.

  1. 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
    Jean-Michel Pichavant, Sep 7, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    795
    Thomas Matthews
    Jan 21, 2005
  2. jamestuck21

    Binary Division Problem Help

    jamestuck21, Nov 30, 2006, in forum: C Programming
    Replies:
    22
    Views:
    1,730
    Al Balmer
    Dec 1, 2006
  3. Replies:
    94
    Views:
    4,463
    ¬a\\/b
    Feb 9, 2007
  4. Chris Angelico

    Re: Division help in python

    Chris Angelico, Sep 7, 2012, in forum: Python
    Replies:
    2
    Views:
    170
    Hans Mulder
    Sep 8, 2012
  5. Serhiy Storchaka

    Re: Division help in python

    Serhiy Storchaka, Sep 7, 2012, in forum: Python
    Replies:
    0
    Views:
    174
    Serhiy Storchaka
    Sep 7, 2012
Loading...

Share This Page