I'm testing big integers in Python; they are implemented as an object with sign and an array of digits. It's, basically, to describe Karatsuba Multiplication, and, for those big integers, I need the same behaviour like oridinary numbers with integer division by 10
, and, there is a problem:
Why, in Python, -22 // 10 = -3
?
Asked
Active
Viewed 812 times
-3

Tom
- 55
- 7
-
4Because `//` is floor division, so rounding **down**, not towards zero.`-22 / 10` is `-2.2`, rounding down makes that `-3`. – Martijn Pieters Jan 27 '19 at 13:15
-
1[Why Python's Integer Division Floors](http://python-history.blogspot.com/2010/08/why-pythons-integer-division-floors.html) – Thierry Lathuille Jan 27 '19 at 13:18
1 Answers
2
Dividing by //
is a floor division.
Floor division goes to the lower number without a .
22 // 10
results to the next lower value2
.-22 // 10
results to the next lower value-3
To do a normal division you can run -22 / 10 This results into
- 2.2

basti500
- 600
- 4
- 20