github.com/goplus/igop@v0.25.0/pkg/cmp/go121_export.go (about)

     1  // export by github.com/goplus/igop/cmd/qexp
     2  
     3  //go:build go1.21
     4  // +build go1.21
     5  
     6  package cmp
     7  
     8  import (
     9  	_ "cmp"
    10  
    11  	"github.com/goplus/igop"
    12  )
    13  
    14  func init() {
    15  	igop.RegisterPackage(&igop.Package{
    16  		Name:   "cmp",
    17  		Path:   "cmp",
    18  		Deps:   map[string]string{},
    19  		Source: source,
    20  	})
    21  }
    22  
    23  var source = "package cmp\n\ntype Ordered interface {\n\t~int | ~int8 | ~int16 | ~int32 | ~int64 |\n\t\t~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |\n\t\t~float32 | ~float64 |\n\t\t~string\n}\n\nfunc Less[T Ordered](x, y T) bool {\n\treturn (isNaN(x) && !isNaN(y)) || x < y\n}\n\nfunc Compare[T Ordered](x, y T) int {\n\txNaN := isNaN(x)\n\tyNaN := isNaN(y)\n\tif xNaN && yNaN {\n\t\treturn 0\n\t}\n\tif xNaN || x < y {\n\t\treturn -1\n\t}\n\tif yNaN || x > y {\n\t\treturn +1\n\t}\n\treturn 0\n}\n\nfunc isNaN[T Ordered](x T) bool {\n\treturn x != x\n}\n"