PDA

View Full Version : float vs. double



jabe
04-18-2001, 01:20 AM
hi,

i looked for some useful math libs around and maybe i have to to write my own. most of the libs i found ( e.g. libmath3d <math3d.sourceforge.net> ) uses completely datatype double.
is this the recommended datatype for matricies and vectors in opengl?
what about performance?
what are accelerated gfx-cards (geforce) using internally and which datatype are they optimized for?
has anybody around made some benchmarks regarding float and double?

jan

martin_marinov
04-18-2001, 02:09 AM
Well, this question was asked and discussed not more than two-three weeks ago. You may search the forum archives about it.

So, quick hints here: GeForce family drivers and HW are optimized for float I think. Float is also faster when using large arrays of data - because it uses half of the memory bandwidth used by double. Double is faster when calculations are performed over small amounts of data(which can fit in L2 cache), since it is more close to the internal fpu format.

Hope this helps
Martin

Michail Bespalov
04-18-2001, 02:45 AM
what are accelerated gfx-cards (geforce) using internally


What is use of such knowledge?
I've heard that GeForce uses 9 bit signed numbers for color culculations.Can it help you to send colors to card in more effective manner? No.
Please correct me if I'm wrong.



which datatype are they optimized for?

Download GeForce Performance FAQ from NVIDIA site

rts
04-18-2001, 08:00 AM
If portability is a concern, float is a "safe bet". Some architectures (PS2, others?) don't do so well with doubles.


Correct me if I'm wrong.

jabe
04-18-2001, 09:41 AM
ok, i'm going to search for this stuff, but i was in hurry...
the datatype is only important for vertex, normal and texture data. colors i will always pass as unsigned chars.
the bandwidth is an important fact i forgot to think about. so i think float is the best choice.

thanks

Sylvain
04-20-2001, 12:29 AM
I personnaly use (short) types for vertex data and (char) -128 to 127 for normals it is just speeding up a bit the GeForce board but the main thing concerns my vertice data size in memory http://www.opengl.org/discussion_boards/ubb/wink.gif
Concerning your 3D math library just look at this http://www.flipcode.com/documents/matrfaq.html

Moreover you should use (float) for your 3D math library and turn on Low precision FPU to speed up things a little bit.. http://www.opengl.org/discussion_boards/ubb/smile.gif

sample:
if (option == VR_LOW_PRECISION){
_asm{
Push Eax
Finit
Fstcw [Esp]
Pop Eax
And Eax, 0fcffh
Push Eax
Fldcw [Esp]
Pop Eax
};
return;
}
_asm{
Push Eax
Finit
Fstcw [Esp]
Pop Eax
And Eax, 0f0ffh
Or Eax, 00c00h
Push Eax
Fldcw [Esp]
Pop Eax
};

Moreover if you want you can also check Amd site for 3DNow code concerning Matrix,Quaternions & Eulers code looks nice but i think 3DNow & SSE support doesn't worst the headache!!

good luck. (&forget doubles)