Skip to content

Commit

Permalink
2024-11-13 15:36:52
Browse files Browse the repository at this point in the history
  • Loading branch information
mohanson committed Nov 13, 2024
1 parent 686585f commit eaef4b7
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pywasm/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1903,6 +1903,7 @@ def evaluate(self) -> None:
case pywasm.opcode.i32_div_s:
b = self.stack.value.pop().into_i32()
a = self.stack.value.pop().into_i32()
assert a != -1 << 31 or b != -1
# Python's default division of integers is return the floor (towards negative infinity) with no
# ability to change that. You can read the BDFL's reason why.
# See: https://python-history.blogspot.com/2010/08/why-pythons-integer-division-floors.html
Expand Down Expand Up @@ -2013,6 +2014,7 @@ def evaluate(self) -> None:
case pywasm.opcode.i64_div_s:
b = self.stack.value.pop().into_i64()
a = self.stack.value.pop().into_i64()
assert a != -1 << 63 or b != -1
c = a // b if a * b > 0 else (a + (-a % b)) // b
d = ValInst.from_i64(c)
self.stack.value.append(d)
Expand Down

0 comments on commit eaef4b7

Please sign in to comment.