Double variable keeping wrong value

前端 未结 4 2027
长情又很酷
长情又很酷 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-28 03:16

    This doesn't seem possible.

    The value of piBy180 * degree is computed almost correctly, off by less than 2 units in the 17th significant digit. The CPU has to perform a multiplication to do this, and it did that in double precision, correctly, even if someone tried to mess up the precision by abusing DirectX calls.

    The value of Val is wrong already at the 8th significant digit. Val is declared as double, and it gets assigned the double value that was computed a microsecond ago, with no further computations in the way.

    Is this a release build? I wonder if C# might have omitted storing the latest value into Val, the way C++ can do. What happens in a debug build?

提交回复
热议问题