Skip to content

reflect: DeepEqual fails for nested NaN values #12025

Closed
@tgpfeiffer

Description

@tgpfeiffer

What version of Go are you using (go version)?

go version go1.4 linux/amd64

What operating system and processor architecture are you using?

Fedora Linux 20, 3.19.8-100.fc20.x86_64 #1 SMP kernel

What did you do?
What did you expect to see?
What did you see instead?

I tried to compare a map that contains NaN values for a fixed key using reflect.DeepEqual and the result was true. I expected false because two NaN values are never equal. reflect.DeepEqual(math.NaN(), math.NaN()) is also false.

package main

import "fmt"
import "math"
import "reflect"

func main() {
    fmt.Println(reflect.DeepEqual(math.NaN(), math.NaN()))

    a := map[string]float64{"a": math.NaN()}
    fmt.Println(reflect.DeepEqual(a, a))

    b := []float64{math.NaN()}
    fmt.Println(reflect.DeepEqual(b, b))
}

outputs:

false
true
true

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions