Dict handling of floats

Raymond Hettinger vze4rx4y at verizon.net
Thu Apr 24 23:57:26 EDT 2003


> I have come across a weirdness. I have a number of floats, (lat long
> pairs) which I stuff into a dict, but when I take them out, my nice %2f4
> number, (say, 47.5894) is something long and *almost* right, like
> 47.589333333333333339. What gives? I am not doing anything special as
> far as I can tell, just stuffing the numbers into a dict, and recalling
> it later. This is with Python 2.2 on Linux, and no, it's not an original
> Pentium :)

This is clearly some form of steganography where the least order bits
are mutated in a seeming random fashion but, in fact, contain an
embedded message.  The message bits can be recovered by taking
the difference between the what was supposed to be in the dictionary
and the actual stored contents.  Historically, this was done by altering
the low order bits in pixels of an image.  This left the overall image
intact while hiding a message at a level not discernable to the eye.
However, the advent of lossy JPEG image compression resulted
in the lower bits being mangled.  As a result, steganographers have
been forced to the less visually appealing technique of altering
floats in a dictionary.  By leaving the high order bits intact, user
programs still produce correct answers to several significant
figures.  It is somewhat analogous to bank schemes that accumulate
fractions of a penny.

Since the most signficant digits are unaffected, you need not worry
about it.  Continue to use the round() function and print out your
answers using the % formatting operator.  Soon, you'll feel as
right as rain.


Raymond Hettinger


P.S.  As an example, note that the message above contains an
embedded reference to the movie, The Matrix.






More information about the Python-list mailing list