-
Notifications
You must be signed in to change notification settings - Fork 17.5k
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
proposal: math: add package math/ints for common operations on integers #41157
Comments
I think if this is added to std library at all its better to wait for generics. There have been previous proposals and discussions about this https://groups.google.com/forum/#!topic/golang-nuts/dbyqx_LGUxM but none was ever accepted. Does this existing package suffice? |
Thanks for the links. Both are useful, although it seems the discussion diverges quickly into generics. I can't really find the reason for why a separate package for these functions would be a bad idea. I have my own package ints of course, so it doesn't really matter that much. It's just strange this is not present in the Go stdlib given its common use. It's weird when learning Go and still weird after two years of using it. Having these function will probably also reduce the complaints about the lack of generics a bit. |
There is an active design draft for generics (https://go.googlesource.com/proposal/+/refs/heads/master/design/go2draft-type-parameters.md). Let's put this proposal on hold until we have either accepted or rejected that design. |
This can be taken off hold. |
Thanks, moved back to incoming. |
The package
math/ints
would functions for common operations on integers:Rationale: although Max, Min and Abs are trivial to implement, they are used so often they probably warrant being in the standard library.
The list above is not meant to be exhaustive, but more of a starting point. The package could also contain constants
IntMax
,IntMin
,Int64Max
,Int64Min
.The text was updated successfully, but these errors were encountered: