-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Closed
Milestone
Description
math/bits.Div
currently makes the behavior undefined if hi >= y
.
func Div(hi, lo, y uint) (quo, rem uint)
We should instead define it to panic in that case.
The compare-and-branch should be cheap relative to the divide itself.
This came up because the current code returns a (weird?) sentinel value in this case. When intrinsifying the code, the raw amd64 opcode will instead cause an arithmetic fault. Both behaviors fit in the "undefined" category, so they are technically spec conforming, but it's really weird for behavior to change when optimization is turned on. Since we'd need a test anyway to unify the behaviors, might as well make the test result panic.
We should resolve this one way or the other for 1.12, before the API goes public.
smasher164, TocarIP, josharian, bronze1man and griesemerbcmills