From ce14b143badc98dbefe995077636594c022bdd02 Mon Sep 17 00:00:00 2001 From: Yiwu Chen <210at85@gmail.com> Date: Wed, 18 Sep 2024 16:58:03 +0000 Subject: [PATCH] [stdlib] Fix `Int.__floordiv__` and friends Signed-off-by: Yiwu Chen <210at85@gmail.com> --- stdlib/src/builtin/int.mojo | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/stdlib/src/builtin/int.mojo b/stdlib/src/builtin/int.mojo index 74bf38c1331..750edbe5883 100644 --- a/stdlib/src/builtin/int.mojo +++ b/stdlib/src/builtin/int.mojo @@ -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 @@ -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 @@ -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: