# How is -6//4 equal to -2?

Normally if i type print(6//4) the result is 1 But, >>>print (-6//4) gives me -2 Why and how does that happen?

12/13/2019 2:47:50 PM

Tausimman Minuha¯\_(ツ)_/¯8 Answers

New AnswerThis question is frequently asked and also anwered. You can read this: https://stackoverflow.com/questions/37283786/floor-division-with-negative-number

I think it could be about modulo operator. Because I assume that: a % b = a - (a // b) * b If we tested -6 % 4 with the formula: -6 % 4 = -6 - (-6 // 4) * 4 If -6 // 4 was -1: -6 - (-1) * 4 = -2 Then we would get -2 which is the wrong remainder. If we always decided to take the lower whole number in case the result would not be a whole number. Then we would assume that -6 // 4 = -2 and calculate the remainder again: -6 - (-2) * 4 = 2 And this is the right remainder. I think this would be good reason to make floor division always choose the lower whole number in case of not getting a whole number.

Since -1 is greater than -2 hence python prints -2 as python rounds the answer off to the nearest small digit

Basically // rounds down to the nearest integer. 6//4=1.5 ~ 1(not 2), as 1<2 -6//4=-1.5 ~ -2(not -1), as -2<-1

Floor function = largest number less than the number. -6/4 = -1.5 the floor function to -1.5 == -2 not -1 because -2<-1.5<-2. ..