Float or Double

Started by
3 comments, last by jonbell 21 years, 5 months ago
What are the pro''s and con''s of using floats or doubles in 3D gfx? Which should i use?
Advertisement
The obvious:

double
- Higher precision

float
- Faster (not always)
- Less memory

For graphics, precision doesn''t matter all that much, which is why floats are often used.

Cédric
The FPU should handle floats and doubles at the same speed. It''s the extra size (read: memory bandwidth used) that causes the difference. When using SIMD instructions, twice as many floats can be processed as doubles.

I agree with Cedric... you most likely won''t need the added precision. Try it out. If you get precision problems, you can always switch to doubles. I''d recommend a simple:

  typedef float real_t;  


Use real_t everywhere. If you find the need to use extra precision, all you need to do is change the typedef.

Kippesoep
How does double multiplication not take more cycles than float multiplication if they are same speed?
AFAIK, the FPU converts from 32bit (or 64bit) to a standard precision (80bit on Intel processors, 64bit on some, though not all, AMD processors) and converts back upon storing. The multiplication is done entirely using those registers, taking 3 clock ticks. Funnily, depending on the state of the floating point control word, division does take a different number of ticks for each precision (19 ticks for 24bit precision, 33 ticks for 53bit precision, 39 ticks for 64bit precision)

These timings are for Pentium/Pentium MMX. The situation is analogous (if a little more complicated) for more recent processors.



[edited by - Kippesoep on November 6, 2002 11:06:52 AM]
Kippesoep

This topic is closed to new replies.

Advertisement