Can floating-point precision be thread-dependent?

前端 未结 1 602
无人共我
无人共我 2021-01-18 13:21

I have a small 3D vector class in C# 3.0 based on struct that uses double as basic unit.

An example: One vector\'s y-value is

-20.0 straight
<         


        
1条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-18 14:09

    Yes, I believe the result can be thread-dependent.

    My guess is you're using DirectX at some point in your code - and that sets the precision for the FPU, and I believe it sets it on a per-thread basis.

    To fix this, use the D3DCREATE_FPU_PRESERVE flag when you call CreateDevice. Note that this will potentially have a performance impact. The managed equivalent is CreateFlags.FpuPreserve.

    (See this related question. I haven't suggested that this one be closed as a duplicate, as they at least look a bit different on the surface. Having both should help the answer to be discoverable.)

    0 讨论(0)
提交回复
热议问题