Math.Log和圆数

时间:2016-09-27 16:47:39

标签: c# math rounding

var result = Math.Log(1000, 10);
var diff = result - 3;

diff约为-4x10^-16

据我所知,确切的值3可以存储在双倍中:

3 (base 10) = 1.1x10^1 (base 2)

我错了还是意味着Math.Log不准确,至少对于值1000?

1 个答案:

答案 0 :(得分:2)

我建议在这种情况下使用Math.Log10

var result1 = Math.Log(1000, 10); //result1: 2.9999999999999996
var result2 = Math.Log10(1000);  //result2: 3