Hi,
I have this small program using Direct 9.0b. The computation of `d1' and `d2' in
`launch' does not give the same results after I've initialized some stuff of
DirectX. Is this normal? A bug somewhere?
Thanks,
Manu
using System;
using System.IO;
using System.Text;
using System.Reflection;
using System.Runtime.InteropServices;
using Microsoft.DirectX.Direct3D;
namespace ConsoleApplication1
{
public class Manu {
public static void Main (){
Manu app = new Manu();
app.launch();
}
public double pi = 3.14159265358979323846;
public void launch () {
double d1, d2;
float f1;
d1 = calc_double (180.0) - pi;
call_directx();
d2 = calc_double (180.0) - pi;
}
public double calc_double (double angle) {
return angle / 180.0 * pi;
}
public void call_directx (){
PresentParameters parameters;
Device render_device;
System.Windows.Forms.Form window;
window = new System.Windows.Forms.Form();
parameters = new PresentParameters();
parameters.Windowed = true;
parameters.SwapEffect = SwapEffect.Discard;
parameters.EnableAutoDepthStencil = true;
parameters.AutoDepthStencilFormat = DepthFormat.D16;
render_device = new Device (0, DeviceType.Hardware, window.Handle,
CreateFlags.SoftwareVertexProcessing, parameters);
}
}
}
Peter Koen - 11 Oct 2003 01:11 GMT
> Hi,
>
[quoted text clipped - 4 lines]
> Thanks,
> Manu
DirectX also initializes some stuff on the fpu, that means the fpu will
perform slightly different rounding and will show different effects on
extrem values. although with normal calculations you shouldn't notice the
difference.
but always remember: "We are pentium of borg, division is futile, you will
be approximated" *g* ;)

Signature
best regards
Peter Koen
-----------------------------------
MCAD, CAI/R, CAI/S, CASE/RS, CAT/RS
http://www.kema.at
Phil Taylor [ATI] - 11 Oct 2003 01:43 GMT
graphics hw works in float. not double.
the DX runtime inits the FPU to what works with graphics hw.
if you require double, then init DX with the FPU_PRESERVE flag.
its a perf hit, but unless you want to manually reset the FPU its the
easiest thing to do.
> Hi,
>
[quoted text clipped - 55 lines]
>
> }
Emmanuel Stapf - 11 Oct 2003 06:30 GMT
> if you require double, then init DX with the FPU_PRESERVE flag.
>
> its a perf hit, but unless you want to manually reset the FPU its the
> easiest thing to do.
How do you do this in managed DirectX?
Thanks,
Manu
Fabian Schmied - 12 Oct 2003 17:47 GMT
> How do you do this in managed DirectX?
Use a Direct3D.Device constructor that takes a CreateFlags value and specify
CreateFlags.FpuPreserve.
Fabian
David Notario [MSFT] - 19 Oct 2003 18:53 GMT
This behavior is bad enough already in C++. In managed code it's a bug to
change any FPU flags. I'll open a bug against the DX guys so that at least
the default is FpuPreserve. How much does this matter nowadays anyways? In
the past the burden of the math computations was done in the CPU in x87
mode. Today, the computations are done in the GPU and/or software vertex
shaders, which are probably done in SSEized code.

Signature
David Notario
Software Design Engineer, CLR JIT Compiler
http://devdiary.xplsv.com
> > How do you do this in managed DirectX?
>
> Use a Direct3D.Device constructor that takes a CreateFlags value and specify
> CreateFlags.FpuPreserve.
>
> Fabian