Skip to content

Commit 1fd3cc7

Browse files
ianlancetaylorgopherbot
authored andcommitted
cmp, builtin: document NaN behavior
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 <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Cuong Manh Le <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]>
1 parent fd353a1 commit 1fd3cc7

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/builtin/builtin.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,14 @@ func make(t Type, size ...IntegerType) Type
210210

211211
// The max built-in function returns the largest value of a fixed number of
212212
// arguments of [cmp.Ordered] types. There must be at least one argument.
213+
// If T is a floating-point type and any of the arguments are NaNs,
214+
// max will return NaN.
213215
func max[T cmp.Ordered](x T, y ...T) T
214216

215217
// The min built-in function returns the smallest value of a fixed number of
216218
// arguments of [cmp.Ordered] types. There must be at least one argument.
219+
// If T is a floating-point type and any of the arguments are NaNs,
220+
// min will return NaN.
217221
func min[T cmp.Ordered](x T, y ...T) T
218222

219223
// The new built-in function allocates memory. The first argument is a type,

src/cmp/cmp.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ package cmp
1010
// that supports the operators < <= >= >.
1111
// If future releases of Go add new ordered types,
1212
// this constraint will be modified to include them.
13+
//
14+
// Note that floating-point types may contain NaN ("not-a-number") values.
15+
// An operator such as == or < will always report false when
16+
// comparing a NaN value with any other value, NaN or not.
17+
// See the [Compare] function for a consistent way to compare NaN values.
1318
type Ordered interface {
1419
~int | ~int8 | ~int16 | ~int32 | ~int64 |
1520
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |

0 commit comments

Comments
 (0)