Skip to content

Commit

Permalink
[stdlib] Fix Int.__floordiv__ and friends
Browse files Browse the repository at this point in the history
Signed-off-by: Yiwu Chen <[email protected]>
  • Loading branch information
soraros committed Sep 18, 2024
1 parent da5bfa5 commit ce14b14
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions stdlib/src/builtin/int.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,8 @@ struct Int(
var div: Int = self._positive_div(denominator)

var mod = self - div * rhs
var divMod = select(((rhs < 0) ^ (self < 0)) & mod, div - 1, div)
div = select(self > 0 & rhs > 0, div, divMod)
var div_mod = select(((rhs < 0) ^ (self < 0)) & mod, div - 1, div)
div = select((self > 0) & (rhs > 0), div, div_mod)
div = select(rhs == 0, 0, div)
return div

Expand All @@ -615,9 +615,9 @@ struct Int(
var div: Int = self._positive_div(denominator)

var mod = self - div * rhs
var divMod = select(((rhs < 0) ^ (self < 0)) & mod, mod + rhs, mod)
var div_mod = select(((rhs < 0) ^ (self < 0)) & mod, mod + rhs, mod)
mod = select(
self > 0 & rhs > 0, self._positive_rem(denominator), divMod
(self > 0) & (rhs > 0), self._positive_rem(denominator), div_mod
)
mod = select(rhs == 0, 0, mod)
return mod
Expand All @@ -635,7 +635,7 @@ struct Int(
if rhs == 0:
return 0, 0
var div: Int = self._positive_div(rhs)
if rhs > 0 & self > 0:
if (rhs > 0) & (self > 0):
return div, self._positive_rem(rhs)
var mod = self - div * rhs
if ((rhs < 0) ^ (self < 0)) & mod:
Expand Down

0 comments on commit ce14b14

Please sign in to comment.