Standard library / cmp
cmp.Compare()
Returns -1, 0 or 1 according to order. NaN compares equal to NaN and below other floats; signed zeros compare equal. Expected stdout: '-1 0 1\n'.
Formal Syntax & Structure
go syntaxgo
func Compare[T Ordered](x, y T) intParameters & Attributes
| Name | Type | Description |
|---|---|---|
| x | T | Input value or collection to process. |
| y | T | Second value to compare. |
Return Value
int
Returns -1, 0 or 1 according to order. NaN compares equal to NaN and below other floats; signed zeros compare equal.
Working Example
Example Snippetgo
package main
import ( "cmp" "fmt")
func main() { fmt.Println(cmp.Compare(3, 7), cmp.Compare(7, 7), cmp.Compare(9, 7))}