System.Convert.ToDouble(十进制)给出两个不同的答案
System.Convert.ToDouble(decimal) giving two different answers
我有一个非常奇怪的问题。我 运行 立即 window:
?(System.Convert.ToDouble(2458963.229671001113318401517D))
2458963.229671001
这是我所期望的!
然后,稍后在我的应用程序中,在初始化 Managed DirectX 之后,我得到以下信息:
?(System.Convert.ToDouble(2458963.229671001113318401517D))
2458963.25
在我的代码中达到那个点之后,在 System.Convert.ToDouble()
之后将永远 return t运行 得到错误的结果。
我已经隔离了导致 System.Convert.ToDouble()
行为发生这种变化的单行:
new Device(adapterOrdinal, dType, this, flags, m_presentParams);
这是一个 Microsoft.DirectX.Direct3D.Device
对象,来自:
// Assembly: Microsoft.DirectX.Direct3D, Version=1.0.2902.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
我不确定为什么创建 Microsoft.DirectX.Direct3D.Device
会导致 System.Convert.ToDouble()
的行为发生变化。
根据https://docs.microsoft.com/en-us/previous-versions/bb324030(v%3Dvs.85):
When a Device object is created, the common language runtime will
change the floating-point unit (FPU) to single precision to maintain
better performance. To maintain the default double precision FPU,
which is default for the common language runtime, use the
CreateFlags.FpuPreserve flag when creating a Device object
我有一个非常奇怪的问题。我 运行 立即 window:
?(System.Convert.ToDouble(2458963.229671001113318401517D))
2458963.229671001
这是我所期望的!
然后,稍后在我的应用程序中,在初始化 Managed DirectX 之后,我得到以下信息:
?(System.Convert.ToDouble(2458963.229671001113318401517D))
2458963.25
在我的代码中达到那个点之后,在 System.Convert.ToDouble()
之后将永远 return t运行 得到错误的结果。
我已经隔离了导致 System.Convert.ToDouble()
行为发生这种变化的单行:
new Device(adapterOrdinal, dType, this, flags, m_presentParams);
这是一个 Microsoft.DirectX.Direct3D.Device
对象,来自:
// Assembly: Microsoft.DirectX.Direct3D, Version=1.0.2902.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
我不确定为什么创建 Microsoft.DirectX.Direct3D.Device
会导致 System.Convert.ToDouble()
的行为发生变化。
根据https://docs.microsoft.com/en-us/previous-versions/bb324030(v%3Dvs.85):
When a Device object is created, the common language runtime will change the floating-point unit (FPU) to single precision to maintain better performance. To maintain the default double precision FPU, which is default for the common language runtime, use the CreateFlags.FpuPreserve flag when creating a Device object