Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Meh using floating point as keys for maps in any language is just asking for trouble -- it’s not just NaN

I don’t think there’s any real use case for it

I’d say clear() is good for clarity, and that’s it



> I don’t think there’s any real use case for it

Histogram where you want to keep a count for each float value you’ve seen (maybe rounded to some precision to reduce the number of buckets)

Not disagreeing with your comment, just saying it’s not uncommon


Why not just multiply each key by ten to the power of your desired precision, then convert to int?

If you're rounding anyway it's basically the same amount of work.


You can certainly map floats to int ‘bin number’ which is the index into an array. No need for a map.

But the ‘naive’ histogram is an example of a map using float keys.


Hm I don't agree that example means it's "not uncommon" -- why would you want to hash the float rather than the bucket number?

Hashing the floats themselves isn't going to give you a useful histogram.

Is there a codebase that hashes float to a useful effect? If it exists, I'd be interested to see it




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: