floats: fix Same for NaN/N

This commit is contained in:
kortschak
2018-01-30 01:16:37 +10:30
committed by Dan Kortschak
parent 870bcdceb6
commit 39ce232e1a
2 changed files with 2 additions and 2 deletions

View File

@@ -706,7 +706,7 @@ func Same(s, t []float64) bool {
}
for i, v := range s {
w := t[i]
if v != w && !math.IsNaN(v) && !math.IsNaN(w) {
if v != w && !(math.IsNaN(v) && math.IsNaN(w)) {
return false
}
}

View File

@@ -1130,7 +1130,7 @@ func TestSame(t *testing.T) {
}
s1 = []float64{1, 2, math.NaN(), 4}
s2 = []float64{1, math.NaN(), 3, 4}
if !Same(s1, s2) {
if Same(s1, s2) {
t.Errorf("Slices with unmatching NaN values returned as equal")
}
}