4 ms·
I 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
by sevensor 8y ago
I 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.