Skip to content
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

Open
markusheukelom opened this issue Sep 1, 2020 · 3 comments
Open

Comments

@markusheukelom
Copy link

@markusheukelom markusheukelom commented Sep 1, 2020

The package math/ints would functions for common operations on integers:

Max(a, b int) int
Min(a, b int) int
Abs(value int) int
Pow(a int, b uint) int

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.

@gopherbot gopherbot added this to the Proposal milestone Sep 1, 2020
@gopherbot gopherbot added the Proposal label Sep 1, 2020
@martisch
Copy link
Contributor

@martisch martisch commented Sep 1, 2020

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

@martisch martisch added this to Incoming in Proposals Sep 1, 2020
@markusheukelom
Copy link
Author

@markusheukelom markusheukelom commented Sep 1, 2020

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.

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Sep 1, 2020

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.

@ianlancetaylor ianlancetaylor moved this from Incoming to Hold in Proposals Sep 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.