Skip to content

fmt: maps with NaN keys are not printed correctly #14427

Closed
@soniakeys

Description

@soniakeys

go version go1.6 linux/amd64

m := map[float64]int{math.NaN(): 3, math.NaN(): 4, .1: 5}
fmt.Println(m)

prints map[0.1:5 NaN:<nil> NaN:<nil>].

I would have hoped for map[0.1:5 NaN:3 NaN:4] since for example iterating over the map with a for loop can retrieve the values 3 and 4. Perhaps acceptable would be map[0.1:5 NaN:0 NaN:0], consistent with v, ok := m[math.NaN()] returning 0, false. But printing when nil is not a valid value for the int type is unexpected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions