Jump to content
  • Advertisement
Sign in to follow this  
Dark Schneider

Working with floating-point precision

This topic is 4075 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I don't recommend to use the D3DCREATE_FPU_PRESERVE flags in IDirect3D9::CreateDevice(), because many errors can happen as usually libraries and drivers suppose that FPU is in single precision as D3D changes it. Another solution, and the best, is that if we want to use 'double' vars (double FPU precision) we can do this: { unsigned int uiTemp=(_controlfp(0,0) & _MCW_PC); //save the FPU precision _controlfp(_PC_53,_MCW_PC); //change to default 64-bit .... code with 'double' data _controlfp(uiTemp,_MCW_PC); //restore } If you try to use 'double' within D3D apps, you can notice that you have 'float' results for 'double' data, because D3D has changed the FPU precision to single.

Share this post


Link to post
Share on other sites
Advertisement
Or more generic:

{
unsigned int uiTemp=_controlfp(0,0); //save the FPU state

_controlfp(); //changes
...
_controlfp(); //changes

.... code with 'double' data

_controlfp(uiTemp,0xffffffff); //restore
}

Share this post


Link to post
Share on other sites
Perhaps a more important question is why you need to use double precision in code that's communicating with D3D in the first place...

I can't think of any game graphics situations where double precision really is the only answer or even most appropriate over single precision.

If you really do have one of those rare cases, it's best to split as much of your code into two parts so that you preserve/toggle/restore the FPCW only as much as is really necessary.

Share this post


Link to post
Share on other sites
Quote:
Perhaps a more important question is why you need to use double precision in code that's communicating with D3D in the first place...


That is not covered in this POST, but as you ask, an aswer could be for exampe an application that uses D3D for screen drawing but that uses complex computations (maybe maths applications?) with high need precision for internal computation.

Quote:
If you really do have one of those rare cases, it's best to split as much of your code into two parts so that you preserve/toggle/restore the FPCW only as much as is really necessary.


That is not exactly what this POST says?, for that the 'code' example is so generic, anyone can later to adapt it to their programs.

Many people don't know that when you create a D3D device it changes the FPU precision, and I think is important to note it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!