diff --git a/stdlib/src/builtin/int.mojo b/stdlib/src/builtin/int.mojo index 74bf38c1331..7bf204f97f4 100644 --- a/stdlib/src/builtin/int.mojo +++ b/stdlib/src/builtin/int.mojo @@ -592,14 +592,11 @@ struct Int( `floor(self/rhs)` value. """ # This should raise an exception - var denominator = select(rhs == 0, 1, rhs) - var div: Int = self._positive_div(denominator) - + var denom = select(rhs == 0, 1, rhs) + var div = self._positive_div(denom) var mod = self - div * rhs - var divMod = select(((rhs < 0) ^ (self < 0)) & mod, div - 1, div) - div = select(self > 0 & rhs > 0, div, divMod) - div = select(rhs == 0, 0, div) - return div + div = select(((rhs < 0) ^ (self < 0)) & mod, div - 1, div) + return select(rhs == 0, 0, div) @always_inline("nodebug") fn __mod__(self, rhs: Int) -> Int: @@ -611,16 +608,11 @@ struct Int( Returns: The remainder of dividing self by rhs. """ - var denominator = select(rhs == 0, 1, rhs) - var div: Int = self._positive_div(denominator) - + var denom = select(rhs == 0, 1, rhs) + var div = self._positive_div(denom) var mod = self - div * rhs - var divMod = select(((rhs < 0) ^ (self < 0)) & mod, mod + rhs, mod) - mod = select( - self > 0 & rhs > 0, self._positive_rem(denominator), divMod - ) - mod = select(rhs == 0, 0, mod) - return mod + mod = select(((rhs < 0) ^ (self < 0)) & mod, mod + rhs, mod) + return select(rhs == 0, 0, mod) @always_inline("nodebug") fn __divmod__(self, rhs: Int) -> Tuple[Int, Int]: @@ -630,17 +622,9 @@ struct Int( rhs: The value to divide on. Returns: - The quotient and remainder as a `Tuple(self // rhs, self % rhs)`. + The quotient and remainder as a tuple `(self // rhs, self % rhs)`. """ - if rhs == 0: - return 0, 0 - var div: Int = self._positive_div(rhs) - if rhs > 0 & self > 0: - return div, self._positive_rem(rhs) - var mod = self - div * rhs - if ((rhs < 0) ^ (self < 0)) & mod: - return div - 1, mod + rhs - return div, mod + return self // rhs, self % rhs @always_inline("nodebug") fn __pow__(self, exp: Self) -> Self: