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

markusheukelom opened this issue Sep 1, 2020 · 3 comments


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
Copy link

@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!topic/golang-nuts/dbyqx_LGUxM but none was ever accepted.

Does this existing package suffice?

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

@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.

Copy link

@ianlancetaylor ianlancetaylor commented Sep 1, 2020

There is an active design draft for generics ( Let's put this proposal on hold until we have either accepted or rejected that design.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

No branches or pull requests

4 participants