Math.Sin给我错误的答案吗?

use*_*141 1 c# math trigonometry

我试图使用Math.Sin()计算sin(pi弧度).我使用以下代码.

        double degrees = 180;
        double radians = Math.PI / 180 * degrees;
        Console.WriteLine(Math.Sin(radians));
Run Code Online (Sandbox Code Playgroud)

它给了我一个价值

1.22460635382238E-16

这是什么原因?当然它应该返回值0对吗?

请赐教.谢谢.

Imm*_*lue 6

1.22460635382238E-16基本上是0.它实际上代表了数字

0.000000000000000122460635382238.这个数字接近于0.这基本上只是因为不同的舍入错误都在一起.

请访问http://en.wikipedia.org/wiki/Floating_point了解更多信息.