Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
fmt: maps with NaN keys are not printed correctly #14427
go version go1.6 linux/amd64
I would have hoped for
This behaviour comes from the reflect package used in fmt to print the map.
reflect MapIndex has the comment:
Btw. i dont think 0, false for m[math.NaN()] is consistent with map[0.1:5 NaN:0 NaN:0] as the earlier means the key was not found and therefore the 0 return value has no relation with the contents of the map.
Yes, this is an unfortunate wart that comes from the combination of NaN and the fact that reflect only provides MapKeys, not MapEntries. MapEntries wouldn't be hard to do, I'd be in favor of doing it. The question is whether it is worth the extra API just to accommodate NaN keys, something that is probably not advisable anyway.
Also see #11104