]> Cypherpunks repositories - gostls13.git/commitdiff
sort: don't depend on math
authorBrad Fitzpatrick <bradfitz@golang.org>
Sun, 21 Apr 2013 00:20:41 +0000 (17:20 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Sun, 21 Apr 2013 00:20:41 +0000 (17:20 -0700)
No reason to pull in math just for x != x.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/8886043

src/pkg/go/build/deps_test.go
src/pkg/sort/sort.go

index 9a715ba601fe7b9f4494ed185a36ca593af80a04..71b1bcf060bfcb1154aef0459ba5022751957fc8 100644 (file)
@@ -47,7 +47,7 @@ var pkgDeps = map[string][]string{
        "math":          {"unsafe"},
        "math/cmplx":    {"math"},
        "math/rand":     {"L0", "math"},
-       "sort":          {"math"},
+       "sort":          {},
        "strconv":       {"L0", "unicode/utf8", "math"},
        "unicode/utf16": {},
        "unicode/utf8":  {},
index e109619924013850b379b720f73ce68cec1fbf72..d3092e8019171d11d76df5d198b87b8739766f99 100644 (file)
@@ -6,8 +6,6 @@
 // collections.
 package sort
 
-import "math"
-
 // A type, typically a collection, that satisfies sort.Interface can be
 // sorted by the routines in this package.  The methods require that the
 // elements of the collection be enumerated by an integer index.
@@ -245,9 +243,14 @@ func (p IntSlice) Sort() { Sort(p) }
 type Float64Slice []float64
 
 func (p Float64Slice) Len() int           { return len(p) }
-func (p Float64Slice) Less(i, j int) bool { return p[i] < p[j] || math.IsNaN(p[i]) && !math.IsNaN(p[j]) }
+func (p Float64Slice) Less(i, j int) bool { return p[i] < p[j] || isNaN(p[i]) && !isNaN(p[j]) }
 func (p Float64Slice) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }
 
+// isNaN is a copy of math.IsNaN to avoid a dependency on the math package.
+func isNaN(f float64) bool {
+       return f != f
+}
+
 // Sort is a convenience method.
 func (p Float64Slice) Sort() { Sort(p) }