5 ms·
I once encountered an old database using floats as its primary keys. This was in a fairly popular piece of manufacturing software from the 90s.
by caseymarquis 8y ago
I once encountered an old database using floats as its primary keys. This was in a fairly popular piece of manufacturing software from the 90s.
- shabbyrobe 8y agoWow, I'd love to hear more about this.
- mcv 8y agoUseful in case you want multiple entries with an id of approximately 1?
- Const-me 8y agoPotentially, might be useful if you want small fixed-length keys that are fast to compare, and also you want to be able to insert new items between existing ones.
- jmiserez 8y agoThere was this article posted a while ago that used a Stern-Brocot tree and/or floats for ordering: https://news.ycombinator.com/item?id=16635440 https://news.ycombinator.com/item?id=16635440 It doesn't work in the pathological case though as any float has a fixed number of bits, and I see the article has been amended with a note.
- maxxxxx 8y agoWhat type of data would that be? I once did this when I did my own primitive version of a geospatial database in the 90s.
- sevensor 8y agoI sometimes, in Python, cautiously use floating point numbers as dictionary keys. I do this when what I mean is "this exact floating-point number" and not "the result of an equivalent computation." It's almost never a good idea, because it's really easy to trip yourself up by assuming the latter when only the former actually holds.
- deleted 8y ago[deleted]
- jmiserez 8y agoAnd even the former apparently isn't guaranteed on all hardware. I found this gem in the Java documentation, I don't know which processors actually do this: >"Arithmetic operations on signaling NaNs turn them into quiet NaNs with a different, but often similar, bit pattern. However, on some processors merely copying a signaling NaN also performs that conversion. In particular, copying a signaling NaN to return it to the calling method may perform this conversion." Source: https://docs.oracle.com/javase/7/docs/api/java/lang/Double.html https://docs.oracle.com/javase/7/docs/api/java/lang/Double.h...
- kazinator 8y agoYou could hardly avoid this if you, say, memoized some function that has floating-point inputs.
- sevensor 8y agoIndeed, and for that reason I'd be very cautious when attempting to memoize a function with floating-point inputs.