locked
Precision of double chaged after init directX device RRS feed

  • Question

  • Hi all,

    I use C#.Net 2003 dot.net 1.1 directX 9 (1.0.2902.0) on Windows Vista or XP sp.2

    could anyone explain me that result:

     

    using System;

    using System.Windows.Forms;

    using Microsoft.DirectX.Direct3D;

    namespace WindowsApplication

    {

    public class Form1 : System.Windows.Forms.Form

    {

    [STAThread]

    static void Main()

    {

    Application.Run(new Form1());

    }

    public Form1()

    {

    PresentParameters pps = new PresentParameters();

    pps.Windowed = true;

    pps.SwapEffect = SwapEffect.Discard;

     

    double aMixX = 68665.3515;

    double aStepX = 0.2855;

     

    double aX1 = aMixX - aStepX;

     

    Device m_device = new Device(0, DeviceType.Hardware, this, CreateFlags.HardwareVertexProcessing, pps);

     

    double aX2 = aMixX - aStepX;

     

    Console.WriteLine(aX1-aX2); // returns 0.00350000010803342

    }

    }

    }

    Saturday, December 1, 2007 10:27 AM

Answers

  • You must use the CreateDevice.FPUPreserve flag when creating the device, because D3D switches to single-precision by default. This might cause some unexpected results, such as degraded performance, though.
    Saturday, December 1, 2007 2:20 PM