]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmp, builtin: document NaN behavior
authorIan Lance Taylor <iant@golang.org>
Sat, 10 Jun 2023 02:59:37 +0000 (19:59 -0700)
committerGopher Robot <gobot@golang.org>
Sun, 11 Jun 2023 00:41:42 +0000 (00:41 +0000)
Add notes for cmp.Ordered and builtin.{min,max}.

Fixes #60648

Change-Id: I81806af2d9a0613befde3f2bbfbc2720f0726912
Reviewed-on: https://go-review.googlesource.com/c/go/+/502235
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>

src/builtin/builtin.go
src/cmp/cmp.go

index 03e90c8a560314eff1065a36d5aff1fb929bbe4a..da0ace1498504ecf29a2b9845feb4c6e93423fe7 100644 (file)
@@ -210,10 +210,14 @@ func make(t Type, size ...IntegerType) Type
 
 // The max built-in function returns the largest value of a fixed number of
 // arguments of [cmp.Ordered] types. There must be at least one argument.
+// If T is a floating-point type and any of the arguments are NaNs,
+// max will return NaN.
 func max[T cmp.Ordered](x T, y ...T) T
 
 // The min built-in function returns the smallest value of a fixed number of
 // arguments of [cmp.Ordered] types. There must be at least one argument.
+// If T is a floating-point type and any of the arguments are NaNs,
+// min will return NaN.
 func min[T cmp.Ordered](x T, y ...T) T
 
 // The new built-in function allocates memory. The first argument is a type,
index 3da8ff457057e868d2b130893d039ae26e7a20a3..0fba5c121162237c080c8aeb1b387fa8142f5330 100644 (file)
@@ -10,6 +10,11 @@ package cmp
 // that supports the operators < <= >= >.
 // If future releases of Go add new ordered types,
 // this constraint will be modified to include them.
+//
+// Note that floating-point types may contain NaN ("not-a-number") values.
+// An operator such as == or < will always report false when
+// comparing a NaN value with any other value, NaN or not.
+// See the [Compare] function for a consistent way to compare NaN values.
 type Ordered interface {
        ~int | ~int8 | ~int16 | ~int32 | ~int64 |
                ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |