Standard library / cmp

cmp.Less()

Reports whether x precedes y, including NaN before non-NaN floating-point values. Expected stdout: 'true false\n'.

Formal Syntax & Structure

go syntaxgo
func Less[T Ordered](x, y T) bool

Parameters & Attributes

NameTypeDescription
xTInput value or collection to process.
yTSecond value to compare.

Return Value

bool

Reports whether x precedes y, including NaN before non-NaN floating-point values.

Working Example

Example Snippetgo
package main
import (  "cmp"  "fmt"  "math")
func main() {  fmt.Println(cmp.Less(math.NaN(), 1.0), cmp.Less(1.0, math.NaN()))}
Go Reference