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
math/bits: add Rem32/Rem64 #28970
Comments
That seems like a reasonable thing to want to have. I don't think we know how to implement such a thing as an intrinsic. The instruction x86 would use will trap if the quotient is too big, regardless of whether you use the quotient or not. |
In that case, I personally would very much want to keep |
Ok, we can decide if we want Rem also (and how to do it, if we do) for 1.13. Note that you can do |
For the 64-bit case, I not sure if you can get around the need to issue two division instructions to get the remainder when
|
@bmkessler : Very nice. |
Based on comments above, sounds like decision is keep panicking and leave Rem32/Rem64 for Go 1.13. Assuming here that Div64 is new in this release, which I think it is. |
Too late to add new API to 1.13. |
Change https://golang.org/cl/197838 mentions this issue: |
Thank you! |
Change https://golang.org/cl/217127 mentions this issue: |
Updates #28970 Updates #36878 Change-Id: I9676f50516dd5b32bd4e44be136fcb9f43776edd Reviewed-on: https://go-review.googlesource.com/c/go/+/217127 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
On current master, math/bits.Div{32, 64} panic when
y <= hi
, i.e. on overflow, as seen in the 979d902.However, even if the quotient might not fit in uint{32, 64}, the remainder does. Therefore I would like to kindly ask you to reconsider because sometimes getting the remainder of uint{64, 128} and uint{32, 64} is still useful, for example in modular arithmetic.
Perhaps there could be additional functions just for remainders, such as
Rem64(hi, lo, y uint64) (rem uint64)
.The text was updated successfully, but these errors were encountered: