-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
checked_rem
and checked_mod
don't follow the same promotion rules as regular rem and mod
#54485
Comments
checked_rem
and checked_mod
don't follow the same promotion rules as regular rem and mod
The promotion rules for
Though also inconsistent that |
wat
Since Julia doesn't widen results of operations beyond their input argument types, the consistent option would be for unsigned dividends with negative divisors to throw a IMO then integer division result should just be the type of the dividend, rather than the current signedness of the dividend and largest width of either argument. For For |
Out of curiosity I looked at what C# does. It's also messy, but does prevent overflow. In C#, all integer division/remainder results are widened to contain all valid results of the input types (e.g. UInt32 ÷ Int8 = Int64), with a minimum of Int32. Only if both are unsigned and at least one argument is 32-bit or larger will it return an unsigned result. If it can't widen further, the operation is not valid. |
It looks like
rem
andmod
have custom promotion rules, to keep the signed-ness of one of their arguments, but the checked_* operations just directly callpromote(x,y)
on the arguments.Probably the checked* operations should be updated to have the same promotion rules as their normal, non-checked operators.
EDIT: Also, this unusual promotion behavior for
rem
andmod
is not documented in the docstrings. Can we please fix that as part of this issue?The text was updated successfully, but these errors were encountered: