Open markusheukelom opened 4 years ago
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? https://github.com/pkg/math
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
.