Math.Sin给我错误的答案吗?(Is Math.Sin giving me the wrong answer? [duplicate])

编程入门 行业动态 更新时间:2024-10-28 06:30:21
Math.Sin给我错误的答案吗?(Is Math.Sin giving me the wrong answer? [duplicate])

这个问题在这里已经有了答案:

Math.Cos&Math.Sin在C# 5中的答案

我正在尝试使用Math.Sin()来计算sin(pi弧度)。 我正在使用下面的代码。

double degrees = 180; double radians = Math.PI / 180 * degrees; Console.WriteLine(Math.Sin(radians));

它给了我一个值

1.22460635382238E-16

这是什么原因? 当然,它应该返回一个值为0的权利?

请赐教。 谢谢。

This question already has an answer here:

Math.Cos & Math.Sin in C# 7 answers

I am trying to calculate sin(pi radians) using Math.Sin(). I am using the following code.

double degrees = 180; double radians = Math.PI / 180 * degrees; Console.WriteLine(Math.Sin(radians));

It is giving me a value of

1.22460635382238E-16

What is the reason for this? Surely it should be returning a value of 0 right?

Please enlighten me. Thanks.

最满意答案

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

0.000000000000000122460635382238。 这个数字接近于0.这基本上只是因为所有不同的舍入错误。

请参阅http://en.wikipedia.org/wiki/Floating_point以获取更多信息。

1.22460635382238E-16 basically is 0. it actually represents the number

0.000000000000000122460635382238. This number is close to 0. It's basically just because of different rounding errors all coming together.

take a look at http://en.wikipedia.org/wiki/Floating_point for more information.

更多推荐

本文发布于:2023-07-15 05:32:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1110704.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:给我   错误   答案   Sin   Math

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!