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: use generics. #58148

Closed
gucio321 opened this issue Jan 30, 2023 · 1 comment
Closed

proposal: math: use generics. #58148

gucio321 opened this issue Jan 30, 2023 · 1 comment

Comments

@gucio321
Copy link
Contributor

While going through math code, I see many functions that's usage could be simplified by using generics.
this will simplify code like this:

var a, b int = 5, 10
var max int
max = int(math.Max(float64(a), float64(b)))

to be just

var a, b int = 5, 10
var max int
max = math.Max(a, b)

because Max declaration could become

func Max[T number](x, y T) T {...}

what the number should be needs to be discussed. My proposal is to make it

type number interface {
   ~int | ~uint | ~float32 | ~float64
}
@gopherbot gopherbot added this to the Proposal milestone Jan 30, 2023
@seankhliao
Copy link
Member

That would be a backwards incompatible change.
In general, see #48287

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Jan 30, 2023
@golang golang locked and limited conversation to collaborators Jan 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants