Re: Math.Pow function returns incorrect value in DX samples.

From: Filip Strugar (ask_me_at_nomail.com)
Date: 05/11/04


Date: Tue, 11 May 2004 13:53:14 +0200

Try setting CreateFlags.FpuPreserve while creating Direct3D device, it
should solve the problem.

"Fabian Schmied" <REMOVETHISfabianDOTschmied@fhs-hagenbergDOTacDOTat> wrote
in message news:%23CFUSxzNEHA.680@TK2MSFTNGP11.phx.gbl...
> Carlton schrieb:
>
> > We have an application that uses the Math.Pow function to calculate a
> > loop of powers to the 10th. For example, the loop would generate:
> > 1, 10, 100, 1000, ..., 10000000000 etc. What is strange is that
> > after creating some Direct3D objects, when we run the loop the values
> > after a certain point do not return the correct value, ie: 1, 10,
> > 100, 1000, ..., 1000000, 99998234, ????
>
> Math.Pow uses the double type, which is a binary floating point type.
> You should be careful when using binary floating point types to
> represent exact decimal numbers
> (http://www.yoda.arachsys.com/csharp/floatingpoint.html). If you need to
> represent exact decimal values, use integers instead and multiply by
> ten. If your numbers exeed the range of the integer types, you can try
> decimal, which is a decimal floating point type.
>
> Why you are only experiencing the problem with DirectX is that Direct3D
> changes the FPU precision. See the recent thread called "Problems with
> doubles" on microsoft.public.win32.programmer.directx.misc.
>
> Fabian