Open
Description
Currently when writing a function involving a generic numeric type, there's no easy way to determine the maximum or minimum possible value of that type, because the math.Min*
and math.Max*
constants are all type-specific.
I propose that we add the following functions to the math
package:
// MinOf returns the minimum possible value of type T.
func MinOf[T contraints.Integer | constraints.Float]() T
// MaxOf returns the maximum possible value of type T.
func MaxOf[T contraints.Integer | constraints.Float]() T
It's currently not possible to write the above functions without using reflection until #45380
is fixed, but here's an approximation:
Metadata
Metadata
Assignees
Type
Projects
Status
Incoming