#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    9
    Rep Power
    0

    Can't understand why???


    Code:
    -18.75 % 8 
    Out[14]: 5.25 
    
    18.75 % 8 
    Out[15]: 2.75
    why is that so???
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    9
    Rep Power
    0
    and this one too...

    13% -5
    Out[16]: -2

    -13 %5
    Out[17]: 2
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Posts
    484
    Rep Power
    33
    In Python the remainder has the sign of the divider (or something like that-you'll have to search for more info). This is handled this way by most computing languages, although I'm not familar with all languages. Using divmod() will explain what happens.
    print divmod(-18, 8) --> (-3, 6) --> -3*8=-24 --> +6=18 Positive remainder

    You might want math.fmod()
    print math.fmod(-11, 5) --> -1.0
    print math.fmod(11, 5) --> 1.0
    Last edited by dwblas; August 23rd, 2013 at 11:39 AM.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2010
    Posts
    153
    Rep Power
    5
    Here's an explanation from the man himself (GVR):
    http://python-history.blogspot.com/2010/08/why-pythons-integer-division-floors.html
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Posts
    484
    Rep Power
    33
    Originally Posted by admoore
    Here's an explanation from the man himself (GVR):
    http://python-history.blogspot.com/2010/08/why-pythons-integer-division-floors.html
    Nice post by GVR. It explains the thought behind the standard, which makes sense once you understand it.

IMN logo majestic logo threadwatch logo seochat tools logo