gpt4 book ai didi

c# - System.Convert.ToDouble(decimal) 给出两个不同的答案

转载 作者:行者123 更新时间:2023-12-04 00:57:09 25 4
gpt4 key购买 nike

我遇到了一个非常奇怪的问题。我在立即窗口中运行此命令:

?(System.Convert.ToDouble(2458963.229671001113318401517D))

2458963.229671001

这正是我所期望的!

然后,稍后在我的应用程序中,初始化 Managed DirectX 后,我得到以下信息:

?(System.Convert.ToDouble(2458963.229671001113318401517D))

2458963.25

在我的代码中达到该点后,System.Convert.ToDouble() 之后将永远返回截断且错误的结果。

我已经隔离了导致 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://learn.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

关于c# - System.Convert.ToDouble(decimal) 给出两个不同的答案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61492591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com