这些函数通常给出结果的无理数,并且可能是通过泰勒级数计算的,但是是否有任何文档说明这些级数重复了多少次?
我在想这是不是罪过:
public double sin(double x,int n){
double res = 0;
for (int i=0;i<n;i++){
res+=Math.pow(x,i)/this.factorial(x);
}
return res;
}
n
应该是什么?
我需要这个,因为我需要自己创建数学函数,所以我应该知道我应该重复这些操作多少次。
谢谢
最佳答案
对于 Java 6,Math
库将它的几个调用(包括 cos
)委托(delegate)给 StrictMath
,在类文档中说:
These algorithms are available from the well-known network library netlib as the package "Freely Distributable Math Library," fdlibm.
所以我用 Google 搜索了 fdlibm , 然后看了一下 k_cos.c
,并且那里的实现近似于 14 次多项式。
关于Java: sin/cos/tan/ln/other precision (for double)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12343377/