因为本文中展示的通用CDF的实施方式是单精度近似的,且已经用双精度替换float,所以仅精确到7或8的有效(十进制)数字。
有关Hart双精度逼近的VB实现,请参见West对累积正则函数的更好逼近的图2。
编辑:将West实现转换为c :
双精度
是双精度计算机
{
staticconstdoublert 2pi=sqrt (4.0 * acos ) 0.0 );
staticconstdoublesplit=7.07106781186547;
staticconstdoublen0=220.206867912376;
staticconstdoublen1=221.213596169931;
staticconstdoublen2=112.079291497871;
staticconstdoublen3=33.912866078383;
staticconstdoublen4=6.37396220353165;
staticconstdoublen5=0.700383064443688;
staticconstdoublen6=3.52624965998911 e-02;
staticconstdoublem0=440.413735824752;
staticconstdoublem1=793.826512519948;
staticconstdoublem2=637.33363378831;
staticconstdoublem3=296.564248779674;
staticconstdoublem4=86.7807322029461;
staticconstdoublem5=16.064177579207;
staticconstdoublem6=1.75566716318264;
staticconstdoublem7=8.83883476483184 e-02;
constdoublez=Fabs(x;
double c=0.0;
if(z=37.0 ) )
{
constdoublee=exp(-z*z/2.0 );
if(z
{
constdoublen=() () () ) zN5 ) zN4 ) zN3 ) zN2 ) zN1 ) zN0;
constdoubled=((() ) ) zm6 ) zm5 ) zm4 ) zm3 ) zm2 ) zm1 ) zm0;
c=e*n/d;
}
else
{
constdoublef=z1.0/(z2.0/) z 3.0/(z 4.0/) z13.0/20.0 ) );
c=e/(rt2pi*f );
}
}
return x=0.0? c : 1-c;
}
请注意,我们将公式重新排序为更熟悉的系列形式和连续分数的近似值。 West代码的最后一个奇怪数字是2&; pi; 的平方根。 我的身份ACOS(0)=&; 通过利用frac12,在第一行推迟到了编译器; &; PI; 水平。
我检查了三次魔术的数字,但是总是输入错误的东西。 如果你发现拼写错误,请评论!
John Cook在他的回答中使用的测试数据的结果是
x phi Mathematica
- 31.3498980316301150 e-0030.00134989803163
- 1.5865525393145702 e-0010.158655253931
0.000000000000000000e-0010.5
0.56.9146246127401301 e-0010.691462461274
2.19.8213557943718344 e-0010.982135579437
从他们同意Mathematica结果的所有数字来看,我实际上得到了小小的安慰。