Merge pull request #946 from stwen77/fix_floor_div

fix floor div for int
This commit is contained in:
coolreader18
2019-05-10 08:25:24 -05:00
committed by GitHub
2 changed files with 6 additions and 1 deletions

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()))
}