CLR JIT optimizations violates causality?

前端 未结 4 1949
既然无缘
既然无缘 2020-12-07 01:21

I was writing an instructive example for a colleague to show him why testing floats for equality is often a bad idea. The example I went with was adding .1 ten times, and co

4条回答
  •  一个人的身影
    2020-12-07 01:56

    My theory that without the ToString line, the compiler is able to statically optimize the function down into a single value and that it somehow compensates for the floating point error. But when the ToString line is added, the optimizer has to treat the float differently because it is required by the method call. That's just a guess.

提交回复
热议问题