在C#中Math.Sin()和Math.Cos()的精度 [英] Accuracy of Math.Sin() and Math.Cos() in C#

查看:5644
本文介绍了在C#中Math.Sin()和Math.Cos()的精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对在CLR的内在三角函数的不精确性非常恼火。大家都知道,

I am terribly annoyed by the inaccuracy of the intrinsic trig functions in the CLR. It is well know that

Math.Sin(Math.PI)=0.00000000000000012246063538223773

而不是0类似的东西用发生Math.Cos(Math.PI / 2)

instead of 0. Something similar happens with Math.Cos(Math.PI/2).

但是,当我做了一长串的计算是在特殊的情况进行评估,以<​​/ P>

But when I am doing a long series of calculations that on special cases evaluate to

Math.Sin(Math.PI/2+x)-Math.Cos(x)

和结果为零对于x = 0.2,但对于x = 0.1不是零(尝试)。另一个问题是,当参数是一个大量,不准确获取比例较大。

and the result is zero for x=0.2, but not zero for x=0.1 (try it). Another issue is when the argument is a large number, the inaccuracy gets proportionally large.

所以我不知道是否有人已编码的三角函数一些更好的表现在C#中与世界分享。是否CLR调用一些标准C数学函数库实现CORDIC或类似的东西?链接:维基百科CORDIC

So I wonder if anyone has coded some better representation of the trig functions in C# for sharing with the world. Does the CLR call some standard C math library implementing CORDIC or something similar? link:wikipedia CORDIC

推荐答案

您需要使用任意精度小数库。的(.NET 4.0有href=\"http://www.extremeoptimization.com/\" rel=\"nofollow\">任意整数类,但不是小数的

You need to use an arbitrary-precision decimal library. (.Net 4.0 has an arbitrary integer class, but not decimal).

一些流行的可供选择:

  • BigNum
  • W3B.Sine

这篇关于在C#中Math.Sin()和Math.Cos()的精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆