IEEE 754 floats

Robert Kern rkern at ucsd.edu
Wed Sep 15 22:42:27 CEST 2004


Dale Huffman wrote:
> Thanks everyone it works... but does this seem like a kludgy (sp?) way
> to do this, or have I just not gotten to PythonThink mode yet.

I would submit that the task of converting an int to a float like that 
is a fairly rare task. It is exceedingly more common to convert a 
sequence of bytes to and from ints/floats. So Python opts for the more 
general solution, which happens to also be the best solution for the 
most common case.

Additionally, the fine details of memory layout for basic types like 
ints and floats *ought* to be hidden from the user. Of course, you can 
still get at them if you need to via the struct module.

If you run into this situation a lot, it's easy enough to write a 
function that encapsulates the kludge.

For getting into PythonThink mode, type "import this" at the interactive 
prompt.

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter



More information about the Python-list mailing list