Skip to content

Commit 4c96ff4

Browse files
sort: document NaN behavior for Float64Slice and friends
Fixes #20540 Change-Id: I440eee02d37b6921613f9ae77875d91eeec48b1e Reviewed-on: https://go-review.googlesource.com/44490 Reviewed-by: Robert Griesemer <[email protected]>
1 parent 1e08191 commit 4c96ff4

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/sort/sort.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@ func (p IntSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
314314
// Sort is a convenience method.
315315
func (p IntSlice) Sort() { Sort(p) }
316316

317-
// Float64Slice attaches the methods of Interface to []float64, sorting in increasing order.
317+
// Float64Slice attaches the methods of Interface to []float64, sorting in increasing order
318+
// (not-a-number values are treated as less than any ordinary number).
318319
type Float64Slice []float64
319320

320321
func (p Float64Slice) Len() int { return len(p) }
@@ -344,7 +345,8 @@ func (p StringSlice) Sort() { Sort(p) }
344345
// Ints sorts a slice of ints in increasing order.
345346
func Ints(a []int) { Sort(IntSlice(a)) }
346347

347-
// Float64s sorts a slice of float64s in increasing order.
348+
// Float64s sorts a slice of float64s in increasing order
349+
// (not-a-number values are treated as less than any ordinary number).
348350
func Float64s(a []float64) { Sort(Float64Slice(a)) }
349351

350352
// Strings sorts a slice of strings in increasing order.
@@ -353,7 +355,8 @@ func Strings(a []string) { Sort(StringSlice(a)) }
353355
// IntsAreSorted tests whether a slice of ints is sorted in increasing order.
354356
func IntsAreSorted(a []int) bool { return IsSorted(IntSlice(a)) }
355357

356-
// Float64sAreSorted tests whether a slice of float64s is sorted in increasing order.
358+
// Float64sAreSorted tests whether a slice of float64s is sorted in increasing order
359+
// (not-a-number values are treated as less than any ordinary number).
357360
func Float64sAreSorted(a []float64) bool { return IsSorted(Float64Slice(a)) }
358361

359362
// StringsAreSorted tests whether a slice of strings is sorted in increasing order.

0 commit comments

Comments
 (0)