github.com/go-playground/pkg/v5@v5.29.1/math/min.go (about)

     1  //go:build go1.18 && !go1.21
     2  // +build go1.18,!go1.21
     3  
     4  package mathext
     5  
     6  import (
     7  	"math"
     8  
     9  	constraintsext "github.com/go-playground/pkg/v5/constraints"
    10  )
    11  
    12  // Min returns the smaller value.
    13  //
    14  // NOTE: this function does not check for difference in floats of 0/zero vs -0/negative zero using Signbit.
    15  func Min[N constraintsext.Number](x, y N) N {
    16  	// special case for float
    17  	// IEEE 754 says that only NaNs satisfy f != f.
    18  	if x != x || y != y {
    19  		return N(math.NaN())
    20  	}
    21  
    22  	if x < y {
    23  		return x
    24  	}
    25  	return y
    26  }