Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem with double floating point values.

0 views
Skip to first unread message

no...@nowhere.com

unread,
Jul 13, 2002, 11:58:03 PM7/13/02
to
I seem to be having a problem with d3d and double floating point
numbers. If I run this code:

double x = 10000.000000000;
double y = 0.0001;
double z = y+x;

at the begining of the program it works fine, z == 10000.000100000 If
I run it after calling CreateDevice to create the D3D device, z ==
10000.000000000 Any thoughts? Does D3D screw around with the
floating point processor registers in some way?

no...@nowhere.com

unread,
Jul 14, 2002, 12:27:30 PM7/14/02
to
I found the problem. Calling the CreateDevice() changes the FPU
precision control word from 53 bits of precision (what a double
normally has) to 24 bits (same as a float). So even though I'm using
doubles, inside the FPU they're being treating as floats. Gotta love
Microsoft!

Is it okay to change the FPU control word back to 53 bits of precision
during the function where I'm using doubles and then back to 24 at the
end of the function? Or is this going to cause problems if an
interupt occurs while the function is running?

MNT

unread,
Jul 14, 2002, 1:39:51 PM7/14/02
to
<no...@nowhere.com> wrote in message
news:ib93ju4duup68flbb...@4ax.com...

> I found the problem. Calling the CreateDevice() changes the FPU
> precision control word from 53 bits of precision (what a double
> normally has) to 24 bits (same as a float). So even though I'm using
> doubles, inside the FPU they're being treating as floats. Gotta love
> Microsoft!
>
> Is it okay to change the FPU control word back to 53 bits of precision
> during the function where I'm using doubles and then back to 24 at the
> end of the function? Or is this going to cause problems if an
> interupt occurs while the function is running?

I haven't used this, but it looks like this is a feature. D3D uses floats
internally & it looks like this is done so that FPU precision state change
is minimal. But you can override this behavior when calling CreateDevice()
by passing it the D3DCREATE_FPU_PRESERVE. This will do what you suggest, but
at a performance penalty. Some docs is at:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dx8_c/direc
tx_cpp/Graphics/Reference/CPP/D3D/Interfaces/IDirect3D8/CreateDevice.asp

no...@nowhere.com

unread,
Jul 14, 2002, 2:31:58 PM7/14/02
to

I looked it up in the D3D docs and it discusses it. Looks like the
best thing to do is set the precision to 53 bits in the function I
need it in, then switch back at the end of the function.

0 new messages