Double variable keeping wrong value

前端 未结 4 2085
长情又很酷
长情又很酷 2021-01-28 02:47

Simimilar problem to Math.Atan2 or class instance problem in C# and add two double given wrong result

It is something that simple lines:

public static S         


        
4条回答
  •  梦如初夏
    2021-01-28 02:55

    It would help if you told us the value of degree then we could try to reproduce the problem...

    Three things:

    • You should expect a certain amount of error in floating point arithmetic. I wouldn't expect this much, but don't expect to see an exact value.
    • String conversions generally won't show you the exact value. I have a file - DoubleConverter.cs - with a ToExactString method which can help diagnose this sort of thing.
    • Is your app using DirectX at all? That can change the processor mode to effectively use 32 bit arithmetic even when you've got doubles in your code. That seems to me to be the most likely cause of the issue, but it's still just a guess really.

    EDIT: Okay, so it sounds like I guessed right, and DirectX is probably the cause. You can pass CreateFlags.FpuPreserve to the Device constructor to avoid it doing this. That will reduce the performance of DirectX, admittedly - but that's a tradeoff you'll need to consider for yourself.

提交回复
热议问题