float / double support in Python?

Chad Netzer cnetzer at mail.arc.nasa.gov
Thu Feb 6 22:11:35 EST 2003


On Thu, 2003-02-06 at 17:57, Isaac To wrote:

> The only benefit of 4-byte floats on real computers is that it consumes less
> space.  Computations done in 4-byte floats are seldom faster than those in
> 8-byte doubles

In graphics applications that are not fill-rate limited, or CPU limited,
using floats for vertex (and other) data, can have a significant
effect.  If nothing else, because sending all the data to a graphics
renderer takes half the bandwith for a float than a double.  Also, the
graphics chips (even expensive ones) tend to work on floats natively,
and would otherwise convert doubles to float (the calculations may then
occur at 'double' precision, but will usually be clipped back down to
float in the end)

Numerics, on the other hand, typically prefers to use doubles, even if
that means sacrificing half your speed, because doubles are just so much
more resistant to effects of badly conditioned matrices and computations
(although doubles are FAR from capable of solving any numerical
stability problems; they are not a panacea).  Still, float is still
commonly used and can make a difference even on modern fast hardware
(again, usually due to memory bandwidth issues)

Fortunately, Numeric Python handles various types of floats and doubles
natively (even if Python the interpreter thinks of a 'float' as a C
double.)  And PyOpenGL interfaces to Numeric's native objects, so things
are quite fast.

-- 
Bay Area Python Interest Group - http://www.baypiggies.net/

Chad Netzer
(any opinion expressed is my own and not NASA's or my employer's)







More information about the Python-list mailing list