float separationn

Bjorn Pettersen BPettersen at NAREX.com
Wed May 15 18:14:38 EDT 2002


> From: Wolfgang Draxinger [mailto:wdraxinger at darkstargames.de] 
> 
> This is not really C/C++ related, but I think this is also a 
> place to ask: I'm currently working on a compressed 3D Object 
> interchange format. With C/C++ its no problem to raw-write 
> the IEEE standard floats the data 
> consists of into files. Now I'm writing some export scripts 
> for blender 
> in python. My problem is, that the python float object 
> doesn't provide a 
> raw-data access. What I need now, is some possibility to 
> construct the 
> IEEE float format from data returned by the standard math 
> functions. I think frexp() is a good start, however this 
> still returns a float 
> value. I'd like to have the raw bits...
> 
> Some ideas?

The struct module should be able to do this (untested):

  import struct
  val = struct.pack('d', 3.14159)

val is then a Python string containing the correct bit pattern..

-- bjorn





More information about the Python-list mailing list