Stefan Behnel wrote: > Dag Sverre Seljebotn wrote: > >> Robert Bradshaw wrote: >> >>> to do a lookup in a Python hashtable you need to >>> >>> (1) Wrap the float in a Python object >>> (2) call __hash__ on that new object >>> >> I hope that isn't what actually happens :-) Floating point and hashes >> don't seem like a good idea. >> > > That certainly depends on the hash function. A float value is not more than > a bunch of bits after all, just like an int or string. It even has the > advantage of being exactly a multiple of 4 bytes large, so a hash function > can actually deploy extremely efficient CPU operations. > Yes, but the hash function to use would in the majority of real world cases depend heavily on the context. Up to what precision should two floats be compared for equality? Since roundoff errors will usually lead to slightly different values for storage and retrieval, unless you're really, really careful. (Always compare floats by abs(a - b) < eps and so on).
(I'd like to hear about actual use cases if there is any though! -- anything I can think of where store/retrieve would make sense is better represented by intervals on the real line than a single float.) It is certainly possible to create hashes which rounds off floats in the right manner, but that's certainly more magic than I hope is embedded in Python's hash/eq -- I'd like to be able to specify my eps in such cases! Dag Sverre _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
