Using floats or doubles?

BlitzMax Forums/OpenGL Module/Using floats or doubles?

ImaginaryHuman(Posted 2009) [#1]
I'm considering making the move to using all Double-precision for everything, rather than use Floats at all. I'm finding that floats don't seem to be very much faster and in many cases doubles seem to be the same speed. I'm on an iMac Intel Core 2 Duo.

I also did some speed tests for reading/writing and doing basic math on various data types. Integers are fastest at math although writing doubles is faster than writing integers to memory, and almost as fast as reading.

I also tried a simple vertex array test with OpenGL and the float and double tests both had practically the same speed. Points and triangles are just as fast with doubles as with floats. I guess a little bit of that is a bottleneck of the graphics card causing the cpu to wait, perhaps. OpenGL was slightly faster drawing double/float triangles than drawing int triangles - presumably because internally it works in floats and would have to convert integers to floats or something?

Has anyone else made the complete jump to using Doubles throughout? Or do you think there is still a usefulness for Float?


Nate the Great(Posted 2009) [#2]
I used to use doubles in my physics engine here. But then I turned them all into floats and it solved many of my bottle necks... then again, I was doing a lot of sqr and dot product with said doubles.


Floyd(Posted 2009) [#3]
Most of what you think is single or double precision calculations are actually done in extended 80-bit registers. This means the only substantial speed advantage for single precision floats is that you are only moving half as much data as with double precision.

It is possible to squeeze out a little more speed by changing the FPU's precision mode so that it actually does only 32-bit calculations. Direct3D does this. But in that case you have no double precision. You can still have double precision variables, but arithmetic is only done to single precision.


JoshK(Posted 2009) [#4]
NVidia has dropped support for 64-bit floats, and OpenGL3 doesn't support them, because no one used them and there was no point.


ImaginaryHuman(Posted 2009) [#5]
I'm leaning towards floats for drawing graphics and doubles or floats for computation, but one issue arises - if you want to use the full range of a double to represent object positions, then how to pass this to gl to get it to draw properly


Nate the Great(Posted 2009) [#6]
if you want to use the full range of a double to represent object positions, then how to pass this to gl to get it to draw properly



simply convert it to a float and then pass it.... the rounding shouldnt make much of a difference unless you are zooming in on something reallly far. and in that case you should use the most comon trick in the book and change the scale. ie: in a game about a bacteria, your scale might be 1 unit = the length of the bacteria. But in a game with people as the characters, 1 unit ~ 1 meter. You should never use 1 unit = 1 meter for a game about bacteria and you should never use 1 unit = the length of a bacteria for a game with people as the characters...