What's the best way to emulate single-precision floating point in python? (Or other floating point formats for that matter?) Just use ctypes?
A:
If your application suits arrays/matrices, you can use numpy with float32
gnibbler
2010-02-09 20:42:23
+1
A:
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).
Alex Martelli
2010-02-09 21:25:26