mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-29 11:14:38 +08:00
Merge pull request #946 from stwen77/fix_floor_div
fix floor div for int
This commit is contained in:
2 files changed
+6
-1
No files matched your search
@@ -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
|
||||
|
||||
@@ -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()))
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user