Documentation
¶
Overview ¶
Package cmp provides types and functions related to comparing ordered values. Based on the cmp package.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compare ¶
Compare returns
-1 if x is less than y, 0 if x equals y, +1 if x is greater than y.
For floating-point types, a NaN is considered less than any non-NaN, a NaN is considered equal to a NaN, and -0.0 is equal to 0.0.
Example ¶
package main
import (
"solod.dev/so/cmp"
"solod.dev/so/fmt"
)
func main() {
fmt.Printf("%d\n", cmp.Compare(1, 2))
fmt.Printf("%d\n", cmp.Compare("a", "aa"))
fmt.Printf("%d\n", cmp.Compare(1.5, 1.5))
}
Output: -1 -1 0
func Equal ¶
func Equal[T comparable](x, y T) bool
Equal reports whether x and y are equal. For floating-point types, a NaN is considered equal to a NaN, and -0.0 is equal to 0.0. For non-ordered types, compares by raw byte value (memcmp).
Example ¶
package main
import (
"solod.dev/so/cmp"
"solod.dev/so/fmt"
)
func main() {
fmt.Printf("%t\n", cmp.Equal(1, 1))
fmt.Printf("%t\n", cmp.Equal("a", "aa"))
fmt.Printf("%t\n", cmp.Equal(1.5, 1.5))
}
Output: true false true
func Less ¶
Less reports whether x is less than y. For floating-point types, a NaN is considered less than any non-NaN, and -0.0 is not less than (is equal to) 0.0.
Example ¶
package main
import (
"solod.dev/so/cmp"
"solod.dev/so/fmt"
)
func main() {
fmt.Printf("%t\n", cmp.Less(1, 2))
fmt.Printf("%t\n", cmp.Less("a", "aa"))
}
Output: true true
Types ¶
Click to show internal directories.
Click to hide internal directories.