Correct way to emulate single precision floating point in python?

numpy has a float32 type.


If numpy (the excellent suggestion of other answers) is inapplicable for you (e.g. because you're in an environment that doesn't allow arbitrary third-party extensions), the array module in Python standard library is fine too -- type code 'f' gives you 32-bit floats. Besides those and the (usual) double precision floats, there isn't much for "other floating point formats" -- what did you have in mind? (e.g. gmpy offers GMP's modest support for floats with much longer, arbitrary bit sizes -- but it's modest indeed, e.g., no trig functions).