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. 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
3. No Profile Picture
Contributing User
Devshed Novice (500 - 999 posts)

Join Date
May 2009
Posts
653
Rep Power
39
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.
4. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

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

Join Date
May 2009
Posts
653
Rep Power
39