Merge pull request #946 from stwen77/fix_floor_div

fix floor div for int
This commit is contained in:
coolreader18 authored and GitHub committed 2019-05-10 08:25:24 -05:00
commit 0a683f2be6
2 files changed
+6 -1

No files matched your search

+4
View File
@@ -64,6 +64,10 @@ assert (2).__rtruediv__(1.0) == NotImplemented
assert (2).__pow__(3.0) == NotImplemented
assert (2).__rpow__(3.0) == NotImplemented
assert 10 // 4 == 2
assert -10 // 4 == -3
assert 10 // -4 == -3
assert -10 // -4 == 2
assert int() == 0
assert int("101", 2) == 5
+2 -1
View File
@@ -260,7 +260,8 @@ impl PyInt {
if objtype::isinstance(&other, &vm.ctx.int_type()) {
let v2 = get_value(&other);
if *v2 != BigInt::zero() {
Ok(vm.ctx.new_int((&self.value) / v2))
let modulo = (&self.value % v2 + v2) % v2;
Ok(vm.ctx.new_int((&self.value - modulo) / v2))
} else {
Err(vm.new_zero_division_error("integer floordiv by zero".to_string()))
}