4 ms·
It is why we decided [2] to exclude floats as map key in bare [1]. Go follows the standard. However, this creates an issue [3]. Indeed, NaN can map to an infin
by conaclos 4y ago
It is why we decided [2] to exclude floats as map key in bare [1].
Go follows the standard. However, this creates an issue [3]. Indeed, NaN can map to an infinite number of values. These values cannot be accessed. +0 and -0 designates a unique key.
JavaScript normalizes -0 to 0, and NaNs are normalized to a canonical NaN. This makes possible to use NaN as a key in a map.
Other implementations could rely on binary comparison.
This is a lot of pain to deal with.
It is better to avoid float comparison or to restrict floats in some way.
[1] https://baremessages.org https://baremessages.org
[2] https://lists.sr.ht/~sircmpwn/public-inbox/%3CCAFFTG-a-Vci%2BkS_d_%3DuaX8kyxszqtB-79pcb5580Z9xw72V5kw%40mail.gmail.com%3E#%3C9dd16aad-ac82-7ea2-2bb0-3c856b4db850@elvinger.fr%3E https://lists.sr.ht/~sircmpwn/public-inbox/%3CCAFFTG-a-Vci%2...
[3] https://github.com/golang/go/issues/20660 https://github.com/golang/go/issues/20660